0
Q:

keys of array exist in array


<?php
$search_array = array('first' => null, 'second' => 4);

// returns false
isset($search_array['first']);

// returns true
array_key_exists('first', $search_array);
?>

6
<?php 
// PHP function to illustrate the use 
// of array_key_exists() 
function Exists($index, $array) 
{ 
    if (array_key_exists($index, $array)){ 
        echo "Found the Key"; 
    } 
    else{ 
        echo "Key not Found"; 
    } 
} 
  
$array = array("ram"=>25, "krishna"=>10,  
                "aakash"=>20, "gaurav"); 
$index = "aakash"; 
print_r(Exists($index, $array)); 
?> 
3
function findKey($array, $keySearch)
{
    foreach ($array as $key => $item) {
        if ($key == $keySearch) {
            echo 'yes, it exists';
            return true;
        } elseif (is_array($item) && findKey($item, $keySearch)) {
            return true;
        }
    }
    return false;
}
0

Tags

New to Communities?

Join the community