findKeyByValue() public static méthode

Example: $array = array( 'k1' => 4, 'k2' => 'd', 'k3' => 0, 9 => 'p' ); $key = Arrays::findKeyByValue($array, 0); Result: k3
public static findKeyByValue ( array $elements, string $value ) : boolean | integer | string
$elements array
$value string
Résultat boolean | integer | string
Exemple #1
0
 /**
  * @test
  */
 public function shouldFindIntZeroInArray()
 {
     //given
     $array = array('k1' => 4, 'k2' => 'd', 'k3' => 0, 9 => 'p');
     //when
     $zeroKey = Arrays::findKeyByValue($array, 0);
     //then
     $this->assertEquals('k3', $zeroKey);
 }
Exemple #2
0
function optionTag($value, $name, $current)
{
    $selected = Arrays::findKeyByValue($current, $value) !== false ? 'selected' : '';
    $value = Strings::isNotBlank($value) ? ' value="' . $value . '" ' : ' value="" ';
    return '<option' . $value . $selected . '>' . $name . '</option>';
}