tidus97 Posted January 17, 2009 Share Posted January 17, 2009 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 More sharing options...
dawsba Posted January 17, 2009 Share Posted January 17, 2009 hows if($userArray["poll".$pollId] == 0){} Link to comment https://forums.phpfreaks.com/topic/141174-solved-joing-2-things-to-make-variable/#findComment-738914 Share on other sites More sharing options...
tidus97 Posted January 17, 2009 Author Share Posted January 17, 2009 excellent Link to comment https://forums.phpfreaks.com/topic/141174-solved-joing-2-things-to-make-variable/#findComment-738918 Share on other sites More sharing options...
phparray Posted January 17, 2009 Share Posted January 17, 2009 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? Link to comment https://forums.phpfreaks.com/topic/141174-solved-joing-2-things-to-make-variable/#findComment-738922 Share on other sites More sharing options...
dawsba Posted January 17, 2009 Share Posted January 17, 2009 phparray??? what a bizare and strange reply...you do know that he only posted a snippet of code?? Link to comment https://forums.phpfreaks.com/topic/141174-solved-joing-2-things-to-make-variable/#findComment-739043 Share on other sites More sharing options...
phparray Posted January 18, 2009 Share Posted January 18, 2009 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. Link to comment https://forums.phpfreaks.com/topic/141174-solved-joing-2-things-to-make-variable/#findComment-739511 Share on other sites More sharing options...
tidus97 Posted January 21, 2009 Author Share Posted January 21, 2009 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. Link to comment https://forums.phpfreaks.com/topic/141174-solved-joing-2-things-to-make-variable/#findComment-741713 Share on other sites More sharing options...
phparray Posted January 21, 2009 Share Posted January 21, 2009 In that case very good! Link to comment https://forums.phpfreaks.com/topic/141174-solved-joing-2-things-to-make-variable/#findComment-741766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.