Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
Check out the new SourceForge HTML5 internet speed test! No Flash necessary and runs on all devices. Also, Slashdot's Facebook page has a chat bot now. Message it for stories and more. ×

Comment Re:Take PHP outside web pages altogether. (Score 2, Informative) 292

$a = array (1, 2, 3, 4);
foreach ($a as &$b) $b++;
foreach ($a as $b) $b++;
print_r ($a);
It is increment twice because after the first loop, $b is still a pointer to the fourth element of $a. Continuing in the code, the second loop will assign the fourth value of $a each value of $a, then increment it. Try debugging it like so:

$a = array (1, 2, 3, 4);
foreach($a as &$b){
$b++;
}
print_r($a);
foreach($a as $b){
print_r($a);
$b++;
print_r($a);
}
print_r($a);
... and you will see what it is doing. Solution: unset your variables before you re-use them.

$a = array (1, 2, 3, 4);
foreach ($a as &$b) $b++;
unset ($b)
foreach ($a as $b) $b++;
print_r ($a);
And for the $$ thing, it seems to do exactly what it is intended for...

[Simple]
$a = "Hello World";
$b = "a";
echo $$b;
//outputs 'Hello World'

[Complex]
$var0 = "Hell";
$var1 = "o wo";
$var2 = "rld!";
$i = "var0";
while(intval($i[3]) <= 2){
echo $$i;
$i[3] = intval($i[3])+1;
}
//outputs 'Hello World!'

Slashdot Top Deals

I consider a new device or technology to have been culturally accepted when it has been used to commit a murder. -- M. Gallaher

Working...