Skip to content

Instantly share code, notes, and snippets.

@eddmann
Last active August 29, 2015 13:56
Show Gist options
  • Save eddmann/9133311 to your computer and use it in GitHub Desktop.
Save eddmann/9133311 to your computer and use it in GitHub Desktop.
<?php
foreach ($users as $user) {
echo $user['name'] . ' [' . $user['address'] . '] (' . $user['age'] . ')';
}
for ($i = 0; $i < count($users); $i = $i + 1) {
echo $users[$i]['name'] . ' [' . $users[$i]['address'] . '] (' . $users[$i]['age'] . ')';
}
$i = 0;
while ($i < count($users)) {
echo $users[$i]['name'] . ' [' . $users[$i]['address'] . '] (' . $users[$i]['age'] . ')';
$i = $i + 1;
}
// The last two could be rewritten for clarity like so.
for ($i = 0; $i < count($users); $i = $i + 1) {
$user = $users[$i]; // store the current user in the $user variable.
echo $user['name'] . ' [' . $user['address'] . '] (' . $user['age'] . ')';
}
$i = 0;
while ($i < count($users)) {
$user = $users[$i]; // store the current user in the $user variable.
echo $user['name'] . ' [' . $user['address'] . '] (' . $user['age'] . ')';
$i = $i + 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment