T

ありがちなforeachと参照渡し

ありがちなPHPの私。

$array = array('Ringo', 'George', 'John', 'Paul');
$new_array = array();
foreach($array as $k => $v){
  $new_array[] =& $v;
}
print_r($new_array);

もちろん、結果は

Array
(
    [0] => Paul
    [1] => Paul
    [2] => Paul
    [3] => Paul
)

Posted by on 12月 15, 2010 in PHP

コメントを残す