fork download
  1. <?php
  2. $myArray = [
  3. 0 => [
  4. "id" => 1,
  5. "title" => 'title1'
  6. ],
  7. 1 => [
  8. "id" => 2,
  9. "title" => 'title2'
  10. ],
  11. 2 => [
  12. "id" => 3,
  13. "title" => 'title3'
  14. ],
  15. 3 => [
  16. "id" => 4,
  17. "title" => 'title4'
  18. ]
  19. ];
  20.  
  21. foreach( $myArray as &$item) {
  22. $item['funcResult'] = myFunc( $item['id']);
  23. }
  24. unset( $item);
  25.  
  26. function myFunc($n) { return 10 * $n; }
  27.  
  28. print_r($myArray);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [id] => 1
            [title] => title1
            [funcResult] => 10
        )

    [1] => Array
        (
            [id] => 2
            [title] => title2
            [funcResult] => 20
        )

    [2] => Array
        (
            [id] => 3
            [title] => title3
            [funcResult] => 30
        )

    [3] => Array
        (
            [id] => 4
            [title] => title4
            [funcResult] => 40
        )

)