开发者

Double associative array or indexed + associative array

开发者 https://www.devze.com 2022-12-24 16:05 出处:网络
I have an array 开发者_开发技巧 apple color: red price: 2 orange color: orange price: 3 banana color: yellow

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


$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];

0

精彩评论

暂无评论...
验证码 换一张
取 消