You are here

function _coder_replace_array_rearrange in Coder 7.2

Same name and namespace in other branches
  1. 7 scripts/coder_format/coder_format.inc \_coder_replace_array_rearrange()

Related topics

File

scripts/coder_format/coder_format.inc, line 1377
Coder format helper functions.

Code

function _coder_replace_array_rearrange($matches) {

  // Retrieve all array items, except the last one.
  preg_match_all('/(.+? => .+?,) /', $matches[3], $items);

  // The original line including array(.
  $return = $matches[1] . $matches[2] . "\n";
  foreach ($items[1] as $item) {

    // All array items, except the last one, with extra indent.
    $return .= $matches[1] . '  ' . $item . "\n";
  }

  // Last array item, with extra indent and comma.
  $return .= $matches[1] . '  ' . $matches[5] . ",\n";

  // Closing parenthesis (on a new line).
  $return .= $matches[1] . ')';
  return $return;
}