056 - array_keys (return the key of an arrayArray
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)
Array
(
[0] => first
[1] => second
[2] => third
[3] => fourth
)
array_key_first first
array_key_lastfourth
array_key_exists1
array_key_existskey_exists 1
Key exists!
<?php
// 056 - array_keys (return the key of an array
echo "</br><span class='myheading'>056 - array_keys (return the key of an array</span></br>";
$color_056 =["red","green","blue","yellow"];
$newArray_056 = array_keys($color_056); //with iA array
echo '<pre>';
print_r($newArray_056);
echo '</pre>';
$color_a_056 =[
"first" =>"red",
"second" =>"green",
"third" =>"blue",
"fourth" =>"yellow"
];
$newArray_a_056 = array_keys($color_a_056); // With aA Array
echo '<pre>';
print_r($newArray_a_056);
echo '</pre>';
$newArray_b_056 = array_key_first($color_a_056); // return first key
echo 'array_key_first <pre>';
print_r($newArray_b_056);
echo '</pre>';
$newArray_c_056 = array_key_last($color_a_056); // return last key
echo 'array_key_last<pre>';
print_r($newArray_c_056);
echo '</pre>';
$newArray_d_056 = array_key_exists("third", $color_a_056); // check if exists
echo 'array_key_exists<pre>';
print_r($newArray_d_056);
echo '</pre>';
$newArray_e_056 = array_key_exists("six", $color_a_056); // check if exists
echo 'array_key_exists<pre>';
print_r($newArray_e_056);
echo '</pre>';
$newArray_f_056 = key_exists("second", $color_a_056); // above short name
echo 'key_exists <pre>';
print_r($newArray_f_056);
echo '</pre>';
/* using if else with above code */
if ($newArray_f_056)
{
echo "Key exists!";
}
else
{
echo "Key does not exist!";
}
echo '</br>';
?>