search a php array for partial string match

后端 未结 12 1456
南方客
南方客 2020-12-30 22:47

I have an array and I\'d like to search for the string \'green\'. So in this case it should return the $arr[2]

$arr = array(0 =>         


        
12条回答
  •  难免孤独
    2020-12-30 23:44

    PHP 5.3+

    array_walk($arr, function($item, $key) {
        if(strpos($item, 'green') !== false) {
            echo 'Found in: ' . $item . ', with key: ' . $key;
        }
    });
    

提交回复
热议问题