/    Sign up×
Community /Pin to ProfileBookmark

difference output of 5 vs 4

Can anyone tell me what would be the output of following code under php 5 and php 4? Any explanation would be appreciated.

[code=html]
function func(&$ak){
return $ak;
}
$a = array(‘a’,’b’,’c’);
foreach(array_keys($a) as $key){
$y = &func($a[$key]);
$z[]=&$y;
}
var_dump($z);
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 31.2009 — I see no dfference:

PHP4

PHP5

PS: This is the exact script I used for each:
[code=php]
<pre><?php
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
printf("Version: &#37;snn", phpversion());
function func(&$ak)
{
return $ak;
}
$a = array('a', 'b', 'c');
foreach (array_keys($a) as $key)
{
$y = &func($a[$key]);
$z[] = &$y;
}
var_dump($z);
?></pre>
[/code]
Copy linkTweet thisAlerts:
@homer_j_simpsonauthorMar 31.2009 — I see no difference either when I dry run the code. This is a question from mock test. It says, output will be different on php4 and php5. I'll quote the question so that you can get the idea of it.

[question]

This code has changed behavior in PHP5. Identify the output of this script as it would have been if PHP4, as well as the new behavior in PHP5.

Answer - choose 2

(a) array('a','a','b')

(b) array('a','b','c')

(c) array('c','b','a')

(d) array('c','c','c')

(e) array('b','b','b')

[/question]
×

Success!

Help @homer_j_simpson spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...