Created
October 26, 2012 11:51
-
-
Save ccheney/3958350 to your computer and use it in GitHub Desktop.
PHP mongodb - list all keys in a collection
This file contains 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
$cursor = $collection->find(); | |
$array = iterator_to_array($cursor); | |
$keys = array(); | |
foreach ($array as $k => $v) { | |
foreach ($v as $a => $b) { | |
$keys[] = $a; | |
} | |
} | |
$keys = array_values(array_unique($keys)); | |
// assuming first key is MongoID so skipping it | |
foreach (array_slice($keys,1) as $key => $value) { | |
echo "<th>" . $value . "</th>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment