0
PHP array_keys() function
I can not understand, why it's output is 6? someone please help. $arr = [ "a" => "php", "b" => "npm", 4 => "foo", "pdo", "bar"]; $keys = array_keys($arr); echo $keys[4]; //output : 6
2 Answers
+ 4
Because
When you specify "4" as key for third element, next element will automatically take "5" as key if you won't specify it.
And the last element will take "6" as you didn't specify it.
array_keys() returns keys of all elements.
$arr = [
"a" => "php",
"b" => "npm",
4 => "foo", "pdo", "bar"];
$keys = array_keys($arr);
//Here $keys = ["a", "b", 4, 5, 6]
echo $keys[4];
+ 1
Thank you so much. Your explanation was so easy.