How to get the second element of an associative array in PHP

2 Answers

0 votes
$arr = array("php"=>"99", "c"=>"108", "c++"=>"31", "python"=>"21");

echo array_keys($arr)[1] . "\n"; 
echo array_values($arr)[1]; 





/*
run:

c
108

*/

 



answered Jun 27, 2022 by avibootz
0 votes
$arr = array("php"=>"99", "c"=>"108", "c++"=>"31", "python"=>"21");

echo next($arr);





/*
run:

108

*/

 



answered Jun 27, 2022 by avibootz

Related questions

...