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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.