There is a getValue () function that takes an array of keys and values from the getArray () function and returns value for key = $ foo (if any).
function getArray() { // Возвращается массив типа: // Array ( // [0] => Array ( [key] => a [value] => а ) // [1] => Array ( [key] => b [value] => б ) // [2] => Array ( [key] => c [value] => в ) // ) } function getValue( $foo ) { $arr = array(); foreach(getArray() as $i) { $arr[$i['key']] = $i['value']; } if ( isset( $arr[$foo] ) ) return $arr[$foo]; else return 'Nope'; }
This code works, but visually I never like it. Is there a way to simplify or improve the getValue function?
While I found only this solution:
function getValue( $foo ) { foreach(getArray() as $i) { if ($i['key'] == $foo) return $i['value']; } return 'Nope'; }