Created
April 23, 2015 21:03
-
-
Save samuraijane/7ca2895d8be894f837dd to your computer and use it in GitHub Desktop.
Key/value pairs in PHP are common so when you need to iterate through an array and return only the value, this is how you do it.
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 | |
$array = array( | |
"Events", | |
"Webinars", | |
"Cloud", | |
"Collaboration", | |
"Innovation", | |
"Tips" | |
) | |
foreach( $array as $key => $value ){ | |
echo $key."\t=>\t".$value."\n"; | |
} | |
// This will return the following: | |
[0] => Events | |
[1] => Webinars | |
[2] => Cloud | |
[3] => Collaboration | |
[4] => Innovation | |
[5] => Tips | |
// But the following | |
foreach( $array as $key => $value ){ | |
echo $value."\n"; | |
} | |
// will return just the values | |
Events | |
Webinars | |
Cloud | |
Collaboration | |
Innovation | |
Tips | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment