fork download
  1. <?php
  2. $array = array(
  3. array('some_middle-level_id' => array('some_low-level_id' => array(
  4. 'entry1' => 'val1_1', 'entry1_2' => 'val1_2', 'entry3' => 'val1_3', 'entry1_4' => 'val1_4', 'entry5' => 'val1_5',
  5. ))),
  6. array('some_middle-level_id' => array('some_low-level_id' => array(
  7. 'entry1' => 'val2_1', 'entry2' => 'val2_2', 'entry3' => 'val2_3', 'entry4' => 'val2_4', 'entry5' => 'val2_5',
  8. ))),
  9. array('some_middle-level_id' => array('some_low-level_id' => array(
  10. 'entry1' => 'val3_1', 'entry2' => 'val3_2', 'entry3' => 'val3_3', 'entry4' => 'val3_4', 'entry5' => 'val3_5',
  11. ))),
  12. );
  13. $another_array = array(
  14. 'bla',
  15. 'blub',
  16. 'lalala',
  17. );
  18.  
  19. $result = array_map(
  20. function ($elem1) use(&$another_array) {
  21. return array_map(
  22. function ($elem2) use(&$another_array) {
  23. return array_map(
  24. function ($elem3) use(&$another_array) {
  25. list(, $val) = each($another_array);
  26. $elem3['entry6'] = $val;
  27. return $elem3;
  28. },
  29. $elem2
  30. );
  31. },
  32. $elem1
  33. );
  34. },
  35. $array
  36. );
  37.  
  38. print_r($result);
  39.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [some_middle-level_id] => Array
                (
                    [some_low-level_id] => Array
                        (
                            [entry1] => val1_1
                            [entry1_2] => val1_2
                            [entry3] => val1_3
                            [entry1_4] => val1_4
                            [entry5] => val1_5
                            [entry6] => bla
                        )

                )

        )

    [1] => Array
        (
            [some_middle-level_id] => Array
                (
                    [some_low-level_id] => Array
                        (
                            [entry1] => val2_1
                            [entry2] => val2_2
                            [entry3] => val2_3
                            [entry4] => val2_4
                            [entry5] => val2_5
                            [entry6] => blub
                        )

                )

        )

    [2] => Array
        (
            [some_middle-level_id] => Array
                (
                    [some_low-level_id] => Array
                        (
                            [entry1] => val3_1
                            [entry2] => val3_2
                            [entry3] => val3_3
                            [entry4] => val3_4
                            [entry5] => val3_5
                            [entry6] => lalala
                        )

                )

        )

)