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

values in array being escaped
I would like to submit some values - back to the same form for checking before processing...

foreach iterator
Hi Guys
Does the foreach loop have an inbuilt iterator ?

limit string by words??
hello all,

I was wonder if there is a function to limit a string by the number of words inste

get font info from a font file
hello,

Does anyone know how to get font info from a font file ... using php of course !
<

Can I use a loop
Hi buddies!

Once again with my doubts here.

Right now I am using this sql stat

Simple Variable Question
Hi everyone.... again,

I am really getting into php still. Learning more every day. I love it

Buggy registration system
Hey, I just started scripting in PHP, and I ran into a few problems.
Code: <?php
includ

PHP form help required
Hi all! Apologies in advance for having to message the forum for help. I know you must get a lot of

Whats wrong with my query?
I am trying to get this query to show the appropriate ticked vehicle roof height, unless no boxs are

Simple PHP/Java Help..
Hi,
I'm trying to build a little program to do with calculating postage. Unfortunately i haven't

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