Answers for "php how to check if array key value pair exists in array"

PHP
22

php key in array exists

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

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

// returns true
array_key_exists('first', $search_array);
?>
Posted by: Guest on June-07-2020
4

php array exists key

<?php
$search_array = array('first' => 1, 'second' => 4);
if (array_key_exists('first', $search_array)) {
    echo "The 'first' element is in the array";
}
?>
Posted by: Guest on March-19-2022

Code answers related to "php how to check if array key value pair exists in array"

Browse Popular Code Answers by Language