Posted By

collin on 11/01/06


Tagged

php array index map


Versions (?)

map_index


 / Published in: PHP
 

A way of compacting an array of arrays into an array of values.

Say you have an NxM matrix, where each child array represents a row, and you want to iterate over the first element in each row: foreach(mapindex(0, $matrix) as $firstelem) ...

  1. function map_index($index, $array)
  2. {
  3. $out = array();
  4. foreach($array as $row)
  5. $out[] = $row[$index];
  6. return $out;
  7. }

Report this snippet  

You need to login to post a comment.