PHP帮助从函数中检索结果时简化IF语句

Let's say i have this function that seeks for a value inside a bidimensional array:

function findValueBi($array, $field, $value, $returnfield)
{
   foreach($array as $key => $product)
   {
      if ( $product[$field] === $value )
         return $product[$returnfield];
   }
   return false;
}

And the bidimensional array looks like this:

Array
(
    [0] => Array
        (
            [number] => 2
            [type] => unimodal
        )

    [1] => Array
        (
            [number] => 6
            [type] => unimodal
        )

    [2] => Array
        (
            [number] => 8
            [type] => multimodal
        )

    [3] => Array
        (
            [number] => 27
            [type] => multimodal
        )

    [4] => Array
        (
            [number] => 29
            [type] => multimodal
        )
)

What the function does, is to look for a given value inside the 'number' key. If it's found, i retrieve its corresponding 'type' key value. For example, if i am looking for the 'number' 29, then i will get the 'type' value "multimodal" (the last item of the array sample). Otherwise, if the value is not found, the function returns false.

So, the way i retrieve this value is as follows:

if(findValueBi($numbers_patterns,'number',$number,'type')!==false){
                $resultado=findValueBi($numbers_patterns,'number',$number,'type');
                return $resultado;
            }
else{ ... }

Is there a better and/or faster way to do this? Is it possible to retrieve the info right inside the if statement? As you can see, I am calling the function twice, so how can i call it once with the if statement???

You could just elect to use it the first time, then use it inside the if:

$resultado = findValueBi($numbers_patterns,'number',$number,'type'); // call it once
if($resultado !== false){
    // use $resultado here 
}