Home > Back-end >  Get the key without the value in foreach loop
Get the key without the value in foreach loop

Time:10-05

I am wondering if it is possible to get the key without the value in foreach loop. I don't use the value anywhere in the code so I would like to exclude it.

so instead of this foreach($array as $key => $value) {

having something like this foreach($array as $key) {

CodePudding user response:

https://www.php.net/manual/en/function.array-keys.php

foreach(array_keys($array) as $key) {
  echo $key;
}
  • Related