Using foreach to print a list of array

Sep 24, 2009 Author: christina

The first example involves using foreach to print a list of array elements along with their numeric index. We get the numeric index by treating it as the element’s key—after all, they are basically the same thing. The following program prints a list of names numbered from 0 to 3: $strVal) { echo $intKey . ’. ’ . $strVal . ’
’; } ?>

The output of this program is as follows:

0. Joe
1.Bill
2.Arnie
3. Harold

tags: Using foreach

views 3792
  1. Add New Comment