chocopi Posted June 28, 2007 Share Posted June 28, 2007 My question today is about using and array like this $var = 'a'; $array = ('a'=>'blah','b'=>'blarg'); $iable = $array[$var]; but in my code below using it like that does not display anything <?php $drop1 = 'w_1'; list($table1, $id1) = split("_", $drop1); //Create an associative array for all possible tables $array = array('B'=>'Body','H'=>'Hats','I'=>'Items','P'=>'Pants','W'=>'Weapons'); sort($array); //Get the actual table name, by indexing the array with the reference from the first query //e.g. if $table1='w', $table1 will now be $array[w] which is weapons echo "goodbyy {$table1}"; // this echos W $table1 = $array[$table1]; echo "heelo {$table1}"; // but this echos nothing ?> Thanks ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/57612-solved-using-array-in-variable/ Share on other sites More sharing options...
cooldude832 Posted June 28, 2007 Share Posted June 28, 2007 you have a lowercase w in w_1 that might be it Link to comment https://forums.phpfreaks.com/topic/57612-solved-using-array-in-variable/#findComment-285159 Share on other sites More sharing options...
Wildbug Posted June 28, 2007 Share Posted June 28, 2007 Use asort() to maintain index association. (Hint: print_r($array) before and after your current sort to see what's happening.) Also, you need to use a capital 'W' as the key since you've defined it that way. Link to comment https://forums.phpfreaks.com/topic/57612-solved-using-array-in-variable/#findComment-285161 Share on other sites More sharing options...
chocopi Posted June 28, 2007 Author Share Posted June 28, 2007 It was meant to be uppecase i just didnt add it Before: Array ( [b] => Body [H] => Hats [i] => Items [P] => Pants [W] => Weapons ) After: Array ( [0] => Body [1] => Hats [2] => Items [3] => Pants [4] => Weapons ) ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/57612-solved-using-array-in-variable/#findComment-285166 Share on other sites More sharing options...
chocopi Posted June 28, 2007 Author Share Posted June 28, 2007 Cheers guys. Thanks Wildbug using asort worked a treat ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/57612-solved-using-array-in-variable/#findComment-285175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.