Search an array for a matching string

前端 未结 7 1304
渐次进展
渐次进展 2021-01-23 01:26

I am looking for away to check if a string exists as an array value in an array is that possible and how would I do it with PHP?

相关标签:
7条回答
  • 2021-01-23 02:16

    You can use PHP's in_array function to see if it exists, or array_search to see where it is.

    Example:

    $a = array('a'=>'dog', 'b'=>'fish');
    
    in_array('dog', $a); //true
    in_array('cat', $a); //false
    
    array_search('dog', $a); //'a'
    array_search('cat', $a); //false
    
    0 讨论(0)
提交回复
热议问题