Jump to content

[SOLVED] using array in variable


chocopi

Recommended Posts

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 ;D

 

~ Chocopi

Link to comment
Share on other sites

It was meant to be uppecase i just didnt add it :P

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.