双关联数组或索引+关联数组

时间:2010-03-27 07:17:51

标签: php arrays

我有一个数组

apple
   color: red   
   price: 2

orange
   color: orange
   price: 3

banana
  color: yellow
   price: 2

当我得到input时,让我们说green apple如何检查它是否存在于数组中并显示其数据(如果存在)。

1 个答案:

答案 0 :(得分:1)

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

这?

您可以使用$fruits[$fruit_name];

按名称查找
相关问题