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
https://forums.phpfreaks.com/topic/57612-solved-using-array-in-variable/
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

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.