PHP multidimensional array search by value

前端 未结 23 3329
情歌与酒
情歌与酒 2020-11-21 04:45

I have an array where I want to search the uid and get the key of the array.

Examples

Assume we have the following 2-dimensional array:

<
23条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 05:46

    I want to check tha in the following array $arr is there 'abc' exists in sub arrays or not

    $arr = array(
        array(
            'title' => 'abc'
        )
    );
    

    Then i can use this

    $res = array_search('abc', array_column($arr, 'title'));
    if($res == ''){
        echo 'exists';
    } else {
        echo 'notExists';
    }
    

    I think This is the Most simple way to define

提交回复
热议问题