How to access the internal level array values in a foreach loop in following scenario?

I've following array called $data:

Array
(
    [op] => edit
    [pt_id] => 4
    [form_submitted] => yes
    [submit] => Update
    [pt_documents_data] => Array
        (
            [0] => Array
                (
                    [pt_doc_title] => Test Document
                    [pt_doc_id] => 6
                    [pt_doc_file_iname] => 
                )

            [1] => Array
                (
                    [pt_doc_title] => New Joining
                    [pt_doc_id] => 7
                    [pt_doc_file_iname] => 
                )

            [2] => Array
                (
                    [pt_doc_title] => Hallo Jolly
                    [pt_doc_id] => 
                    [pt_doc_file_iname] => FAQ.doc
                )

        )

)

Now I want to access every array and elements contained in it coming under the subarray [pt_documents_data]. I tried to print the first value using foreach but I'm not able to print it. Not understanding where I'm going wrong. Can anyone please help me in accessing the internal arrays one by one? Thanks in advance. My attempt is as follows:

   foreach($data['pt_documents_data'] as $key => $title){
      echo $data[$key]['pt_doc_title']; die;
   }

Actually it is expected to print the value Test Document but it's not printing anything. In a same manner I want to access every element from all the arrays coming under array [pt_documents_data].

Answers


 foreach($data['pt_documents_data'] as $key => $title){
  echo $title['pt_doc_title']."<br />";
   }

Try this:

foreach($data['pt_documents_data'] as $key => $title){
  echo $title['pt_doc_title'];

}


reference $title instead of $data:

foreach($data['pt_documents_data'] as $key => $title){
      echo $title['pt_doc_title'];
   }

foreach($data['pt_documents_data'] as $doc){
  echo $doc['pt_doc_title'];
}

Need Your Help

Snapchat-like swipe navigation between views in Xcode 6 and Swift)

ios xcode swift swipe snapchat

I've been trying to implement swipe navigation between View Controllers in my app using the Swipe Gesture Recognizer and embeded Navigation Controller, but it doesn't look even close to the Snapcha...

Use XML URL as View in Lotus Notes

xml url view lotus-notes

I have a plain vanilla XML output that I want to display in Lotus Notes as a view. Is there a way to use the XML URL as the basis for a view?