0

I currently have the following object in php:

  "Direction": "Please choose the direction"
  "Media": "Please choose the stock"
  "Coating": "Please choose the coating"

I then loop through it with a foreach

foreach ($product as $key => $att) {
// is there away I can get the index?  Meaning 0, 1, etc?
}

In the foreach is there away I can get the index? I need a numerical index value.

FabricioG
  • 3,107
  • 6
  • 35
  • 74
  • 2
    If you don't need the current assoc key, you can do `foreach (array_values($product) as $key => $value)` and $key should now be numeric. Otherwise you'll just need to create your own counter and increment it as you loop through them – rjdown Mar 05 '21 at 19:14

1 Answers1

2
$i = 0;
foreach ($product as $key => $att) {
    echo "index is: $i<br>";
    $i++;
}
Usman Ahmed
  • 2,392
  • 1
  • 20
  • 17