/    Sign up×
Community /Pin to ProfileBookmark

for loop to re-create existing variable

Hello all,
trying to use a for loop to loop thru some variables but i can’t ‘rebuild’ the variable in the loop.

[CODE]
for($x=0; $x<$max; $x++){

if($varname_$x != “”){ //actual variable names are varname_0, varname_1, etc.

array_push($arr, $varname_$x);

}

}
[/CODE]

any ideas? thanks!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@scragarSep 07.2008 — [code=php]for($x=0; $x<$max; $x++){
$tmp = ${'varname_'.$x};
if($tmp != ""){
array_push($arr, $tmp);
}
}[/code]
Copy linkTweet thisAlerts:
@kreddauthorSep 07.2008 — ah, thanks man. i *KNEW* it had something to do with the curly brackets! ha ?
×

Success!

Help @kredd 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.18,
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,
)...