Check if a specific value exists at a specific key in any subarray of a multidimensional array

前端 未结 13 2190
梦毁少年i
梦毁少年i 2020-11-27 18:42

I need to search a multidimensional array for a specific value in any of the indexed subarrays.

In other words, I need to check a single column of the multidimension

13条回答
  •  执念已碎
    2020-11-27 19:25

    I came upon this post looking to do the same and came up with my own solution I wanted to offer for future visitors of this page (and to see if doing this way presents any problems I had not forseen).

    If you want to get a simple true or false output and want to do this with one line of code without a function or a loop you could serialize the array and then use stripos to search for the value:

    stripos(serialize($my_array),$needle)

    It seems to work for me.

提交回复
热议问题