xxxxxxxxxx
<?php
$search_array = array('first' => null, 'second' => 4);
// returns false
isset($search_array['first']);
// returns true
array_key_exists('first', $search_array);
?>
xxxxxxxxxx
<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
echo "The 'first' element is in the array";
}
?>
xxxxxxxxxx
$myArray = array(
"key1" => "value1",
"key2" => "value2",
"key3" => "value3"
);
if (array_key_exists("key2", $myArray)) {
echo "The key 'key2' exists in the array.";
} else {
echo "The key 'key2' does not exist in the array.";
}
xxxxxxxxxx
<?php
$a=array("fruit"=>"Apple","Car"=>"BMW");
if (array_key_exists("Apple",$a)){
echo "Array Key exists!";
}else{
echo "Array Key does not exist!";
}
?>
xxxxxxxxxx
<?php
$search_array = array('first' => null, 'second' => 4);
// returns false
isset($search_array['first']);
// returns true
array_key_exists('first', $search_array);
?>
xxxxxxxxxx
<?php
// The values in this arrays contains the names of the indexes (keys)
// that should exist in the data array
$required = array('key1', 'key2', 'key3');
$data = array(
'key1' => 10,
'key2' => 20,
'key3' => 30,
'key4' => 40,
);
if (count(array_intersect_key(array_flip($required), $data)) === count($required)) {
// All required keys exist!
}