[ create a new paste ] login | about

Link: http://codepad.org/cnCVeZG1    [ raw code | output | fork ]

PHP, pasted on Oct 16:
<?php

echo "foreach as value:\n";

$a = array('hello', 'world');
$ontime = 0;
foreach($a as $i => $v)
{
    if (!$ontime++) $a = array('hash', 'the cat');
    echo " $i: $v\n";
}

echo "\nforeach as reference:\n";

$a = array('hello', 'world');
$asRef =& $a;
$ontime = 0;
foreach($asRef as $i => $v)
{
    if (!$ontime++) $a = array('hash', 'the cat');
    echo " $i: $v\n";
}


Output:
1
2
3
4
5
6
7
8
foreach as value:
 0: hello
 1: world

foreach as reference:
 0: hello
 0: hash
 1: the cat


Create a new paste based on this one


Comments: