-1

我有以下数组结构:

$CATEGORIES = array(
    array(
        category => "music", 
        color => "#FF8800"
        ),
     array(
        category => "film & TV", 
        color => "#59AF56"
        ),
    array(
        category => "culture", 
        color => "#fc2525"
        ),
    array(
        category => "science/tech", 
        color => "#5da9d4"
        )
    );

基本上,将查找类别,我需要检索十六进制值。我找不到任何可以为多维数组执行此操作的东西(在尝试使用 array_search() 之后)。任何指针将不胜感激。

4

1 回答 1

1

尝试这个:

$category = 'culture';
foreach($CATEGORIES as $key){
   if($key['category'] == $category)
      $hex = $key['color'];//here is your color
}

演示

于 2013-08-27T17:24:45.633 回答