tags:

views:

84

answers:

1

I have an array

apple
   color: red   
   price: 2

orange
   color: orange
   price: 3

banana
  color: yellow
   price: 2

When I get input, let's say green apple how do I check if it exists in the array and display its data (if it exists).

+1  A: 
$fruits = array(
    'apple' => array(
        'color' => 'green',
        'price' => 3
    ),
    'banana' => array(
        'color' => 'yelo',
        'price' => 2
    ),
);

That?

You can look up by name using $fruits[$fruit_name];

Coronatus
Why can't you ignore the color and just use the second word?
Coronatus
Yes, see http://docs.php.net/foreach
VolkerK