fork download
  1. <?php
  2.  
  3. class Test
  4. {
  5. public function index( )
  6. {
  7. $arr = array(
  8. array('a' => 'aap', 'n' => 'noot', 'm' => 'mies'),
  9. array('a' => 'ding', 'b' => 'flof', 'c' => 'bips'),
  10. array( 'd' => 'do', 'e' => 're', 'c' => 'mi')
  11. );
  12.  
  13. $func = array( $this, '_user_func' );
  14.  
  15. var_dump($arr); // BEFORE WALK
  16. array_walk_recursive($arr, $func);
  17. var_dump($arr); // AFTER WALK
  18. }
  19.  
  20. /**
  21. * Does something to a row from an array (notice the reference)
  22. */
  23. private function _user_func( &$rowValue, $rowIndex )
  24. {
  25. $rowValue = 'replaced';
  26. }
  27. }
  28.  
  29. $test = new Test();
  30. $test->index();
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  array(3) {
    ["a"]=>
    string(3) "aap"
    ["n"]=>
    string(4) "noot"
    ["m"]=>
    string(4) "mies"
  }
  [1]=>
  array(3) {
    ["a"]=>
    string(4) "ding"
    ["b"]=>
    string(4) "flof"
    ["c"]=>
    string(4) "bips"
  }
  [2]=>
  array(3) {
    ["d"]=>
    string(2) "do"
    ["e"]=>
    string(2) "re"
    ["c"]=>
    string(2) "mi"
  }
}
array(3) {
  [0]=>
  array(3) {
    ["a"]=>
    string(8) "replaced"
    ["n"]=>
    string(8) "replaced"
    ["m"]=>
    string(8) "replaced"
  }
  [1]=>
  array(3) {
    ["a"]=>
    string(8) "replaced"
    ["b"]=>
    string(8) "replaced"
    ["c"]=>
    string(8) "replaced"
  }
  [2]=>
  array(3) {
    ["d"]=>
    string(8) "replaced"
    ["e"]=>
    string(8) "replaced"
    ["c"]=>
    string(8) "replaced"
  }
}