/    Sign up×
Community /Pin to ProfileBookmark

I want to change data that everyone be 100 years old. But it doesn’t work. What’s wrong, please help! Thanks.

[code=php]
<?php
foreach (arr_1(“Rembo” => 24, “Rokky” => 40) as &$v) {
$v = 100;
echo “$k is $v years old<br>”;
}
?>
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 11.2015 — Did you mean to have "array(" where you have "arr_1("?
Copy linkTweet thisAlerts:
@ginerjmJan 11.2015 — And - where is $k defined? And - you do realize that this will not permanently update the contents of your array? And - did you read the Manual on the foreach function? Lots of knowledge in there!
Copy linkTweet thisAlerts:
@WebtorauthorJan 11.2015 — I want to redo this code:
[code=php]
<?php
$arr_1["Rembo"] = 24;
$arr_1["Rokky"] = 40;
foreach ($arr_1 as $k=>&$v) {$v = 100;
echo "$k is $v years old<br>";}
?>
[/code]

into this (but it does not work):
[code=php]
<?php
foreach ($arr_1("Rembo" => 24, "Rokky" => 40) as $k=>&$v) {
$v = 100;
echo "$k is $v years old<br>";

}
?>
[/code]

What's wrong with it?
Copy linkTweet thisAlerts:
@ginerjmJan 11.2015 — You can't update an array that doesn't actually exist. You have to have an array defined outside of the for loop in order to update the results and have them once the loop is done.
Copy linkTweet thisAlerts:
@WebtorauthorJan 12.2015 — I see, thank you.
×

Success!

Help @Webtor 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 5.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...