PHP Forum

How can use this array as a key?

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.
Advertisement

0 answers

No answers posted yet. Be the first to answer.

Your answer

Login to answer

Trending today: see what people are reading