PHP Pass by reference error after using same var

前端 未结 3 811
暖寄归人
暖寄归人 2021-01-15 01:40

Take a look to this code, and help me to understand the result

$x = array(\'hello\', \'beautiful\', \'world\');
$y = array(\'bye bye\',\'world\', \'harsh\');         


        
3条回答
  •  温柔的废话
    2021-01-15 02:26

    // ...
    $v = "DONT CHANGE!";
    unset($v);
    // ...
    

    because $v is still a reference, which later takes the last item in the last foreach loop.

    EDIT: See the reference where it reads (in a code block)

    unset($value); // break the reference with the last element

提交回复
热议问题