Search Multidimensional Array in PHP

前端 未结 2 1288
感动是毒
感动是毒 2021-01-16 06:14

How can I search the following multidimensional array for the string \'uk\'?

array(43)
{
  [0]=> array(1) { [\"country\"]=> string(9) \"Australia\" }
          


        
2条回答
  •  没有蜡笔的小新
    2021-01-16 06:26

    If you are using (PHP 5 >= 5.5.0) there is a better and simple way:

    if(array_search('UK', array_column($array, 'country')) !== false ){
        echo 'found';
    }else{
        echo 'Not found';
    }
    

提交回复
热议问题