function admin_menu_expand_args in Administration menu 7.3
Same name and namespace in other branches
- 8.3 admin_menu.inc \admin_menu_expand_args()
Create the cartesian product of multiple varying sized argument arrays.
Parameters
$arguments: A two dimensional array of arguments.
See also
1 call to admin_menu_expand_args()
- admin_menu_merge_tree in ./admin_menu.inc 
- Walk through the entire menu tree and merge in expanded dynamic menu links.
File
- ./admin_menu.inc, line 302 
- Menu builder functions for Administration menu.
Code
function admin_menu_expand_args($arguments) {
  $replacements = array();
  // Initialize line cursors, move out array keys (placeholders) and assign
  // numeric keys instead.
  $i = 0;
  $placeholders = array();
  $new_arguments = array();
  foreach ($arguments as $placeholder => $values) {
    // Skip empty arguments.
    if (empty($values)) {
      continue;
    }
    $cursor[$i] = 0;
    $placeholders[$i] = $placeholder;
    $new_arguments[$i] = $values;
    $i++;
  }
  $arguments = $new_arguments;
  unset($new_arguments);
  if ($rows = count($arguments)) {
    do {
      // Collect current argument from each row.
      $row = array();
      for ($i = 0; $i < $rows; ++$i) {
        $row[$placeholders[$i]] = $arguments[$i][$cursor[$i]];
      }
      $replacements[] = $row;
      // Increment cursor position.
      $j = $rows - 1;
      $cursor[$j]++;
      while (!array_key_exists($cursor[$j], $arguments[$j])) {
        // No more arguments left: reset cursor, go to next line and increment
        // that cursor instead. Repeat until argument found or out of rows.
        $cursor[$j] = 0;
        if (--$j < 0) {
          // We're done.
          break 2;
        }
        $cursor[$j]++;
      }
    } while (1);
  }
  return $replacements;
}