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

Help on query replacing the date
Hi Pals,

i want to replace the current date in a column to some value say C or D or any n

error help - Dynamic Image
I've been working on making my site less cluttered in the directories and more secure lately. In an

problem getting my contact form working
Yeah I know this is a pretty basic problem, but it's been a while since I've worked with PHP and I'm

help with image upload code
Hello,

right now this code I have resizes images and then places them into the uploads folder

HELP with mysql_real_escape_string
I'm looking to remove apostrophes completely when someone enters lyrics but don't have a clue how to

Reg Ex
Im trying to search for the string: srv_9 (Dead ???)

I thought to use preg_match, however I d

Displaying a clickable playername
I am going wrong somewhere with the mysql_query, can someone please put me straight?

$playern

User registration and login
I don't know whether this is the correct forum, if not i apologise but am pretty desperate at the mo

Create or replace package is ending ORA-21700
Database 9.2.0., patch 8 (9.2.0.8.0).
I trying run
create or replace package ....etc.

Help with usergroups? prolly really quick
So were coding our own forums for a game system we made an we have the users level setup but now I n

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