You are here

function coder_replace_array_rearrange in Coder 6

Same name and namespace in other branches
  1. 5.2 scripts/coder_format/coder_format.inc \coder_replace_array_rearrange()
  2. 5 scripts/coder_format/coder_format.inc \coder_replace_array_rearrange()
  3. 6.2 scripts/coder_format/coder_format.inc \coder_replace_array_rearrange()

Related topics

1 string reference to 'coder_replace_array_rearrange'
coder_postprocessor_array_rearrange in scripts/coder_format/coder_format.inc

File

scripts/coder_format/coder_format.inc, line 1372

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;
}