Jump to content

[SOLVED] joing 2 things to make variable


tidus97

Recommended Posts

hi guys. i have:

 

$joinUserPoll = "poll".$pollId;
$joinUserPoll = $userArray[$joinUserPoll];

if ($joinUserPoll == 0){
//stuff
}

 

which works fine, but i would like to know if there is a way to just do all that in the if area.. that is, within

if (here) {

}

 

i was thinking something like:

 

if (${"userArray['poll".$pollId."']"} == 0) {

//stuff

}

 

but it doesnt work.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/141174-solved-joing-2-things-to-make-variable/
Share on other sites

You can concatenate to create a key if that is what you want to do. 

 

$userArray['poll'.$pollId];

 

Your code never sets the value of $userArray[$joinUserPoll] and even though your code may appear to work you may not realize it meets the if condition because $joinUserPoll is evaluating to false not the integer 0 is that what you intended?

phparray??? what a bizare and strange reply...you do know that he only posted a snippet of code??

 

I totally understand.  My point is this.  His few lines of code set a variable as a key but without setting a value for that combination of array and key there is no point in evaluating it. So I was attempting to find out why he was doing so. Hence my asking "is that what you intended?".  I'm not sure why that's strange.  I'd be interested to here your thoughts on his code snippet.

 

You can concatenate to create a key if that is what you want to do. 

 

$userArray['poll'.$pollId];

 

Your code never sets the value of $userArray[$joinUserPoll] and even though your code may appear to work you may not realize it meets the if condition because $joinUserPoll is evaluating to false not the integer 0 is that what you intended?

 

na it works. userarray is defined earlier. every poll alters the user table and adds another row:

 

'poll'+its id. so poll with id 1 will add poll1 to the user table. now i check to see if this users 'poll1' value (in this case) is 0. 0 means he hasnt voted. 1 means he has. if it equals 0, he can go ahead and vote. else we do something else.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.