Friday, 5 March 2021

PHP 7 Iterate through array, array gets copied, the copied key and values become global

 $a = ['a' => 'hi', 'b' => 'andrew'];


foreach ($a as $key => $val) {

    if ($key == 'a') {

        break;

    }

}


echo $key;

echo $val;


// Result 

'a';

'hi';

No comments:

Post a Comment