How to use PHP in_array with associative array?

前端 未结 6 1701
夕颜
夕颜 2020-12-03 00:15

Is there any php function such as in_array for associative arrays you get by the mysql function \"mysql_fetch assoc\" ?

For example, if I have an $array that looks l

6条回答
  •  孤街浪徒
    2020-12-03 00:51

    Here is a one liner you can use.

    $isInArray = in_array(1, array_column($names, 'ID'));
    

提交回复
热议问题