How can use this array as a key?


Posted on 16th Feb 2014 07:03 pm by admin

Say I have this array for example:


print_r($array);

Prints:
Code: [Select]Array
(
[0] => Array
(

[status] => 0

)

[1] => Array
(
[status] => 1

)

[1] => Array
(
[status] => 0

)
)

Now I have another array:

$color_array = array('0'=>'nocolor','1'=>'green');

How I can do the logic of this?


foreach($array as $tmp){

// Say status holds "1" in this case so it translate to
//$color_array[1]; = green
echo "{$color_array[$tmp['status']]}";

}


Obviously the above generate Illegal offset type. So I cant do that.

No comments posted yet

Your Answer:

Login to answer
221 Like 17 Dislike
Previous forums Next forums
Other forums

Custom Container in module pool program
Hello everyone,

I have created a custom control in my module pool screen. Now I want to s

gmmktime or mktime
I live in the UK, i am within the GMT (with daylight saving time ie 1 hour difrence between summer a

firefox wouldnt stream mp3 files completely from my php page
hi everyone,
I have a php file trying to read and stream mp3 files. It works fine in IE but my pr

How can you detect variable string in a massive string?
Ok guys, i need some help with this one.

I am going to be getting a large string, like 10-20

Wierd echo error?
Hi, i got the most wierd php error ever and i don't know why..
Code: echo "<t

Parse XML
Good day,

I use oempro software and try to parse XMLReturn but it's not working for me, simpl

Checking if variable is 0 as opposed to NULL/Empty...
I'm trying to write some code that will retrieve a user's access level from my database and if it do

send() and recv() parameters confusion
On server Side:
int recv (Socket,Buffer, Length, Flags)
On Client Side:
int send (Soc

Help with page encoding issue and weird characters
I'm trying to write a screen scraper and when I pull out the lines of the html file that I'm interes

Help with writing "$" with fopen
I just can't get my syntax correct. Could someone help me please? I am trying to write a connect fil

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash