Home:ALL Converter>PHP-Mongodb: How to check the nested array exist or not

PHP-Mongodb: How to check the nested array exist or not

Ask Time:2014-12-18T14:34:48         Author:Shaggie

Json Formatter

I am working on backend with mongodb & php. I have stored message content in mongodb database. My mongodb database content is this

 .......some content.........
    "content": "This is the test message",
    "time_created": 1418813065,
    "status": "read",
    "agencyStatus": "read",
    "reply": [
    {
      "email": "[email protected]",
      "name": "Accenture",
      "content": "Thanks for your test message",
      "time": 1418813145
    }
  ]

In my program i am retriving the message content & reply content through foreach loop as is nested as a object inside.

<?php echo $mongoMessage['content'];?>
<?php foreach ($mongoMessage['reply'] as $mongoReply){ ?>
<?php echo $mongoReply['content']; ?>

My problem is when a record with reply exist i am retriving then it is displaying on browser but a record with no reply, i am retriving then it shows me notice on browser. How to get rid of this situation. This problm i am facing from last week plz help me guys...

Author:Shaggie,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/27540526/php-mongodb-how-to-check-the-nested-array-exist-or-not
yy