3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arrA = array('a' => array('x' => 100), 'b' => array('x' => 200), 'c' => array('x' => 300)); // Array of Arrays $arrO = json_decode('[{"id": 1, "val": 10}, {"id": 2, "val": 20}, {"id": 3, "val": 30}]'); // Array of Objects foreach ($arrA as &$val) $val['x'] += 2; // this doesnt work (variable $val) unset($val); //foreach ($arrA as &$val2) $val2['x'] += 2; // this works (renamed reference variable) foreach ($arrO as $val) { foreach ($arrA as $item) error_log($item['x']); // last item in $arrA changed from Array to Object in array $arrO !!! break; // other itteration resulted in same error (last item changed) }

preferences:
22.13 ms | 475 KiB | 4 Q