php compare array keys, not values
Posted
by user271619
on Stack Overflow
See other posts from Stack Overflow
or by user271619
Published on 2010-05-26T22:19:49Z
Indexed on
2010/05/26
22:21 UTC
Read the original article
Hit count: 298
I am successfully using the array_key_exists(), as described by php.net
Example:
<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
echo "The 'first' element is in the array";
}
?>
But, take out the values, and it doesn't work.
<?php
$search_array = array('first', 'second');
if (array_key_exists('first', $search_array)) {
echo "The 'first' element is in the array";
}
?>
Not sure how to only compare 2 arrays by their keys only.
© Stack Overflow or respective owner