Inside a document I want to store unique phone numbers for each person in my collection like so:
phones: {
"5551112222": {
extension: "101",
type: "Mobile"
},
"8005554444": {
extension: "225",
type: "Work"
},
},
name: {
first: "john",
last: "smith"
}
My PHP code to access this, which lets me access the extension and type, but how do I access the number part as $d obviously does not work as it just returns the whole array?
foreach ($cursor['phones'] as $d) {
echo 'number: ' . $d . '<br />ext. ' . $d['extension'] . '<br />type: ' . $d['type'];
According to your
var_dumpoutput of the$cursor['phones']variable:Change your code to:
The reason is simple, when using the
foreachloop in the following format:$dwill contain the Value of the pair.From the php manual:
http://php.net/manual/en/control-structures.foreach.php