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);
Did you know?Explore Trending and Topic pages for more stories like this.

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

urldecode question
How would I format this line of code properly?

<?php echo urldecode($_GET['Title']); ?

Google voice
I currently have a form in html, but I want it in php so the information is not in the source code.<

quick question
Hi ..

i have a question
how do i set a var so it displays via an echo
Code: $logo = '&a

HTML Email rec'd as Source Code
The code does create and send the email successfully. However, the message shows as html code and n

Do not allow posting of whitespace
Currently the script below works if the user does not type a name/message, but if i create a whitesp

Operating System
How in PHP or other language can I detect Operating system, ie Windows XP Home, Windows 7 Ultimate,

Calander layout
Hi i know this sounds like a simple question but i cant find the answer to it anywhere i have added

Transaction variant for VA02 not working
My requirement is to have transaction for user to only add the output and print a sales order.

BI in Upstream Production operations
Appreciate if you can assist in the following areas:
1) Examples of life before and after BI i

How to Handle more than one submit button in single form?
Hi
I have one PHP file which contains one Form. In this form there are two Submit type Buttons

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