How to get all the keys of an associative array in PHP

2 Answers

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




/*
run:

Array
(
    [0] => php
    [1] => c
    [2] => c++
    [3] => python
)

*/

 



answered Jun 26, 2022 by avibootz
0 votes
$arr = array("php"=>"99", "c"=>"108", "c++"=>"31", "python"=>"21");
 
foreach($arr as $key => $value) {
    echo $key . "\n";
}




/*
run:

php
c
c++
python

*/

 



answered Jun 26, 2022 by avibootz

Related questions

1 answer 132 views
1 answer 160 views
1 answer 182 views
2 answers 146 views
1 answer 118 views
2 answers 132 views
...