Created
November 3, 2014 01:23
-
-
Save senmu/dc7c5aecd3aeed904b95 to your computer and use it in GitHub Desktop.
Print out elements in an alternating fashion from two arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Sample arrays | |
| $dribbble = array("dribbble item 1", "dribbble item 2", "dribbble item 3"); | |
| $instagram = array("instagram 1", "instagram 2", "instagram 3", "instagram 4", "instagram 5"); | |
| // Determine maximum size to iterate to | |
| $maxSize = max(count($dribbble), count($instagram)); | |
| for ($i = 0; $i < $maxSize; $i++) { | |
| // Check that attempting to access from the dribbble array is not out of | |
| // bounds | |
| if (count($dribbble) > $i) { | |
| // Print out the list item HTML | |
| echo sprintf("<li>%s</li>\n", $dribbble[$i]); | |
| } | |
| // Check that attempting to access from the instagram array is not out of | |
| // bounds | |
| if (count($instagram) > $i) { | |
| // Print out the list item HTML | |
| echo sprintf("<li>%s</li>\n", $instagram[$i]); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment