1

I use

foreach($terms as $one)
    {
        print $one."<br>";
    }

But this only prints the values. What about the keys?

alex
  • 479,566
  • 201
  • 878
  • 984
Ahmad Farid
  • 14,398
  • 45
  • 96
  • 136
  • 1
    This has been answered lots of times before. Try to use the search field on the top right next time. – devius Jan 04 '11 at 12:44
  • Please familiarize yourself with the [Language Reference in the PHP Manual](http://de.php.net/manual/en/langref.php), especially the [chapter on control structures](http://de.php.net/manual/en/language.control-structures.php) and the [subchapter on foreach](http://de.php.net/manual/en/control-structures.foreach.php) – Gordon Jan 04 '11 at 14:25

1 Answers1

7
foreach($terms as $key => $one)
{
    print $key . ' ' . $one . '<br>';
}

By adding $key => to the foreach, you will be able to access the key as $key above.

alex
  • 479,566
  • 201
  • 878
  • 984