0

I want to print all array and embedded array elements one by one...

Db structure:

  Users: [
        { 
           "_id" : "1", 
           "uname" : "Eminem", 
           "pro_img" : [ "img1", "img2", "img3" ]   // this values
           "gener" : "rap",
           "about" :
                [
                  { "child_name" : ["child1", "child2" , "child3"] },   // and this values
                  {"dob" : "15-07-1970"}

                ] 
         },

        { 
          "_id" : "2", 
          "uname" : "Armin", 
          "pro_img" : [ "img21", "img23", "img34" ]
        }
]

I write the code following way

<?php 
      include 'vendor/dbcon.php';
      $documentlist = $Users-> find(
                       ['uname' => "Eminem"],
                       ['projection' =>  ['_id' => 0, 'pro_img' => 1]]
                    );
        foreach ($documentlist as $doc) {
        echo var_dump($doc);
    }
?>

Output

object(MongoDB\Model\BSONDocument)#14 (1) { 
   ["storage":"ArrayObject":private]=> array(1) { 
   ["pro_img"]=> object(MongoDB\Model\BSONArray)#10 (1) { 
   ["storage":"ArrayObject":private]=> array(3) { 
   [0]=> string(4) "img1" [1]=> string(4) "img2" [2]=> string(4) "img3" } } } }

But I want to store in following way:

$info= array("img1", "img2", "img3");

Also the embedded values with same condition ['uname' => "Eminem"]

$info= array("child1", "child2", "child3");

so that i can use it as a simple php array...

Nakul23
  • 57
  • 2
  • 9

0 Answers0