Skip to content

Instantly share code, notes, and snippets.

@samuraijane
Created April 23, 2015 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuraijane/7ca2895d8be894f837dd to your computer and use it in GitHub Desktop.
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.
<?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