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 227 views
1 answer 239 views
1 answer 268 views
2 answers 252 views
1 answer 199 views
2 answers 256 views
...