jueves, 8 de diciembre de 2016

checking if a key and value exist

<?php

$r = array('a', 'robert', 'c', 'd', 'e'=>"robert");


print_r(array_keys($r,'robert'));

 ?>
check if the value robert exist and return an array with  the key  where each value is found


Array ( [0] => 1 [1] => e )

robert is on key 1 and key e



a more complex a sample and clean example

<?php

$r = array('a', 'robert', 'c', 'd', 'e'=>"robert");


if($key=array_keys($r,'robert'));

foreach($key as $value) {

echo $value."<br>";
}

this will return only the keys name
1
e

No hay comentarios:

Publicar un comentario