Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Your array
- $friends = array(
- array ('fname' => 'Dana', 'lname' => 'Severance', 'email' => 'dana.severance@gmail.com'),
- array ('fname' => 'Chris', 'lname' => '', 'email' => 'laskey@gmail.com'),
- array ('fname' => 'Cory', 'lname' => 'Honkala', 'email' => ''),
- );
- // Your foreach
- foreach ($friends as $friends) {
- echo "Here should be the name: " . $friends[$i]['fname'] . "<br /> Number: " . $i . "<br /><br />";
- $i++;
- }
- // Same loop, different variable names for clarity and to illustrate a point
- foreach ($friends as $key => $value) { // could also be foreach ($friends as $value) {
- // for each loop through the array, two variable are initialized, one, $key, holds the key, and $value holds the value of that spot in the array
- // So, the [$i] part of your code points to a non-existant array
- echo "Here should be the name: " . $value['fname'] . "<br />Number: ". $i ."<br /><br />";
- // $value => Array ('fname' => 'Dana', 'lname' => 'Severance', 'email' => 'dana.severance@gmail.com'),
- // On iteration two, $value => Array ('fname' => 'Chris', 'lname' => '', 'email' => 'laskey@gmail.com'),
- // On iteration three, $value => Array ('fname' => 'Cory', 'lname' => 'Honkala', 'email' => '')
- }
Add Comment
Please, Sign In to add comment