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

Frustrated php Newbie
First off, I am pretty much a PHP nub. I can read and understand the language (most of the time) so

Rounding a number queried from a database
I know that to display a rounded number you just do echo "round($number)";. But how would

SCO Unix
I know this might not be the place to ask, but, can anyone tell me if SCO Unix comes with PHP built

empty() error
Why does

Code: empty($USER_ID = $_SESSION["USER_ID"])
create this error...

How to schedule the a job?
Hi,
I have prepared a task ( i.e. a procedure is prepare the file and send the same to con

Multi language - seo links
Im trying to figure out the best method to have a multi language website that will function with seo

I need desperate help with this php code integrated with flash please
Can someone please help me with this php code which I have been stuck on for weeks . I am trying to

losing session vars when arriving from an email link
Hi,

I've got a confirmation script made that sends an email with a link for a user to confirm

preg_replace question
Hello!!

I hope someone can help me with preg_replace.

I load two tables from an extern

Login Control?!
I have a Web Site that uses the login control also I have set the destinationurl to the page I want

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