Kolob Canyon Kolob Canyon - 2 years ago 92
PHP Question

Php - Fastest method to loop through associative array keys

I only need to loop through the keys of the associative array.

Is this syntax the quickest way to do it?

foreach (arr as $key => $value) {

I'm not going to use
at all.

All I need is

Answer Source

If you run a static analysis with a tool like like PHP Mess Detector against that code it will report you have an unused variable.

If all you want are the keys then use array_keys() to get the keys and then loop through them.

foreach (array_keys($arr) as $key) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download