Jump to content

array_map a 3D array


smith.james0

Recommended Posts

How do you array_map a 3d array

I am using this piece of code

[code]function Q($n){ return("\"$n\""); }

$vals=implode(",",array_map("Q", $book));

echo $vals;[/code]

with this array

Array
(
    [1] => Array
        (
            [0] => 1166313600
            [1] => huihuihui
            [2] => ui
            [3] => iuhi
            [4] => uhiuh
            [5] => hui
            [6] => hui
            [7] => u
            [8] => ihui
            [9] => iu
            [10] => iuhuih
            [11] => iuh
        )

    [2] => Array
        (
            [0] => 1166400000
            [1] => iuh
            [2] => uih
            [3] => uih
            [4] => ih
            [5] => uihu
            [6] => h
            [7] => ih
            [8] => ih
            [9] => h
            [10] => uhih
            [11] => ihui
        )

    [3] => Array
        (
            [0] => 1166486400
            [1] => iu
            [2] => iu
            [3] => iu
            [4] => h
            [5] => iui
            [6] => hiu
            [7] => hiu
            [8] => h
            [9] => h
            [10] => uih
            [11] => iuhi
        )
etc...

I have tried using foreach, but it still returns [1] ad not the rest, can anyone point me in the right direction?

Many Thanks James
Link to comment
https://forums.phpfreaks.com/topic/31022-array_map-a-3d-array/
Share on other sites

I haven't tried this myself.  But's in the user submitted notes on www.php.net/array_map.

[code]
function array_map_recursive($func, $arr)
{
  $result = array();
  do
  {
      $key = key($arr);
      if (is_array(current($arr))) {
          $result[$key] = array_map2($func, $arr[$key]);
      } else {
          $result[$key] = $func(current($arr));
      }   
  } while (next($arr) !== false);
  return $result;
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/31022-array_map-a-3d-array/#findComment-143150
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.