On php.net the manual for the function.array-key-first shows the exemple below.
<?php
$array = ['a' => 1, 'b' => 2, 'c' => 3];
$firstKey = array_key_first($array);
var_dump($firstKey);
?>
The above example will output:
string(1) "a"
What I want to know is how could we echo 'a' with it's value 1. The output would be a1.
As I was writing this I actually found a way to do it, however I can't find anything explaining why it works. Could someone explain to me why it works and if it's valid?
<?php
// Enter your code here, enjoy!
$array = ['a' => 1, 'b' => 2, 'c' => 3];
$firstKey = array_key_first($array);
echo array_key_first($array);
echo $array[array_key_first($array)];
?>
Result for 8.1.10:
a1