Check if associative array contains value, and retrieve key / position in array

前端 未结 3 1071
無奈伤痛
無奈伤痛 2021-01-02 18:05

I\'m struggling to explain what I want to do here so apologies if I confuse you.. I\'m just as confused myself

I have an array like so:

$foo         


        
3条回答
  •  时光说笑
    2021-01-02 18:34

    Taking a guess at what you would like here:

    function findTextByValueInArray($fooArray, $searchValue){
        foreach ($fooArray as $bar )
        {
            if ($bar['value'] == $searchValue) {
                return $bar['text'];
            }
        }
    }
    

提交回复
热议问题