Please give me some advice. when foreach traverses a 3D array, he can only traverse the first child level. why?

Source: Internet
Author: User
Please give me some advice. when foreach traverses a 3D array, he can only traverse the first child level. why?
 $ Val) {?>
 Onclick = "task (
 ,'
 ') ">
 
 
 
 
 

& Amp; workcenter_id = & Plan_id = '"Id =" show "> View


Reply to discussion (solution)

A 3D array requires three nested foreach traversal methods.

But the child nodes under my first parent node can be traversed.

It's not very clear about your data structure. check whether this condition is met.
If (is_array ($ val [$ key])

Your outer loop is
Foreach ($ monitorList as $ key => $ val)
The condition for entering the inner loop is
If (is_array ($ val [$ key])
When the condition is not met, no output is required.


You should at least
Var_export ($ monitorList );
Paste the result to see

0 => array ('id' => '000000', 'create _ uid' => '000000', 'create _ date' => '2017-01-30 09:48:10. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 09:48:10. 000 ', 'name' => 'c # Advanced Programming', 'Plan _ type' => '000000', 'parent _ id' => '0 ', 'Date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', 'product _ qty' => '1', 'Plan _ ctor '=> '', 'status' => '2', 'routing _ id' => '000000', 'Bom _ id' => '1 ', 'Oe _ production_id '=> '0', 'note' => '', 'curr _ id' => NULL, 'Oe _ ean13' => '123 ', 'workcenter _ id' => NULL, 'ischild '=> 1, 'Plan _ director_name' => '', 0 => array (0 => array ('id' => '000000', 'create _ uid' => '000000 ', 'create _ date' => '2017-01-30 09:48:11. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 09:48:11. 000 ', 'name' => 'c # Advanced Programming _ xyd process group 1', 'Plan _ type' => '123 ', 'parent _ id' => '000000', 'date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', 'product _ qty' => NULL, 'Plan _ ctor '=> '', 'status' => '1', 'routing _ id' => '1', 'Bom _ id' => NULL, 'Oe _ production_id '=> NULL, 'note' => 'oo ', 'curr _ id' => NULL, 'Oe _ ean13' => NULL, 'workcenter _ id' => NULL ,), 1 => array ('id' => '000000', 'create _ uid' => '000000', 'create _ date' => '2017-01-30 09:49:20. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 09:49:20. 000 ', 'name' => 'c # Advanced Programming _ xyd process Group 2', 'Plan _ type' => '123 ', 'parent _ id' => '000000', 'date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', 'product _ qty' => NULL, 'Plan _ ctor '=> '', 'status' => '1', 'routing _ id' => '2', 'Bom _ id' => NULL, 'Oe _ production_id '=> NULL, 'note' => 'pp ', 'curr _ id' => NULL, 'Oe _ ean13' => NULL, 'workcenter _ id' => NULL,), 1 => array ('id' => '123', 'create _ uid' => '123 ', 'create _ date' => '2017-01-30 14:45:00. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 14:45:00. 000 ', 'name' => 'Java advanced programming', 'Plan _ type' => '000000', 'parent _ id' => '0 ', 'Date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '6', 'product _ qty' => '1', 'Plan _ ctor '=> '', 'status' => '1', 'routing _ id' => '000000', 'Bom _ id' => '6 ', 'Oe _ production_id '=> '0', 'note' => '', 'curr _ id' => NULL, 'Oe _ ean13' => '123 ', 'workcenter _ id' => NULL, 'ischild '=> 1, 'Plan _ director_name' => '', 0 => array (0 => array ('id' => '000000', 'create _ uid' => '000000 ', 'create _ date' => '2017-01-30 14:45:00. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 14:45:00. 000', 'name' => 'Java advanced programming _ Java Advanced Programming-Times package-Operation package 1', 'Plan _ type' => '123 ', 'parent _ id' => '000000', 'date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '6', 'product _ qty' => NULL, 'Plan _ ctor '=> '', 'status' => '4', 'routing _ id' => '8', 'Bom _ id' => NULL, 'Oe _ production_id '=> NULL, 'note' => '', 'curr _ id' => '000000', 'Oe _ ean13 '=> NULL, 'workcenter _ id' => NULL,), 2 => array ('id' => '123', 'create _ uid' => '123 ', 'create _ date' => '2017-01-30 14:48:38. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 14:48:38. 000 ', 'name' => 'Java advanced programming', 'Plan _ type' => '000000', 'parent _ id' => '0 ', 'Date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '6', 'product _ qty' => '1', 'Plan _ ctor '=> '', 'status' => '1', 'routing _ id' => '000000', 'Bom _ id' => '6 ', 'Oe _ production_id '=> '0', 'note' => '', 'curr _ id' => NULL, 'Oe _ ean13' => '123 ', 'workcenter _ id' => NULL, 'ischild '=> 1, 'Plan _ director_name' => '', 0 => array (0 => array ('id' => '000000', 'create _ uid' => '000000 ', 'create _ date' => '2017-01-30 14:48:38. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 14:48:38. 000', 'name' => 'Java advanced programming _ Java Advanced Programming-main package-Operation package 1', 'Plan _ type' => '123 ', 'parent _ id' => '000000', 'date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '6', 'product _ qty' => NULL, 'Plan _ ctor '=> '', 'status' => '8', 'routing _ id' => '7', 'Bom _ id' => NULL, 'Oe _ production_id '=> NULL, 'note' => '', 'curr _ id' => NULL, 'Oe _ ean13 '=> NULL, 'workcenter _ id' => NULL,), 3 => array ('id' => '123', 'create _ uid' => '123 ', 'create _ date' => '2017-01-30 14:51:45. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 14:51:45. 000 ', 'name' => 'c # Advanced Programming', 'Plan _ type' => '000000', 'parent _ id' => '0 ', 'Date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', 'product _ qty' => '1', 'Plan _ ctor '=> '', 'status' => '1', 'routing _ id' => '000000', 'Bom _ id' => '1 ', 'Oe _ production_id '=> '0', 'note' => '', 'curr _ id' => NULL, 'Oe _ ean13' => '123 ', 'workcenter _ id' => NULL, 'ischild '=> 1, 'Plan _ director_name' => '', 0 => array (0 => array ('id' => '000000', 'create _ uid' => '000000 ', 'create _ date' => '2017-01-30 14:51:45. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 14:51:45. 000 ', 'name' => 'c # Advanced Programming _ C # Advanced Programming-main Package', 'Plan _ type' => '123 ', 'parent _ id' => '000000', 'date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', 'product _ qty' => NULL, 'Plan _ ctor '=> '', 'status' => '2', 'routing _ id' => '5', 'Bom _ id' => NULL, 'Oe _ production_id '=> NULL, 'note' => '', 'curr _ id' => NULL, 'Oe _ ean13 '=> NULL, 'workcenter _ id' => NULL,), 4 => array ('id' => '123', 'create _ uid' => '123 ', 'create _ date' => '2017-01-30 15:12:48. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 15:12:48. 000 ', 'name' => 'c # Advanced Programming', 'Plan _ type' => '000000', 'parent _ id' => '0 ', 'Date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', 'product _ qty' => '1', 'Plan _ ctor '=> '', 'status' => '1', 'routing _ id' => '000000', 'Bom _ id' => '1 ', 'Oe _ production_id '=> '0', 'note' => 'ld', 'curr _ id' => NULL, 'Oe _ ean13 '=> '20150 ', 'workcenter _ id' => NULL, 'ischild '=> 1, 'Plan _ director_name' => '', 0 => array (0 => array ('id' => '000000', 'create _ uid' => '000000 ', 'create _ date' => '2017-01-30 15:12:48. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 15:12:48. 000 ', 'name' => 'c # Advanced Programming _ main Package', 'Plan _ type' => '123', 'parent _ id' => '123 ', 'Date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', 'product _ qty' => NULL, 'Plan _ ctor '=> '', 'status' => '5', 'routing _ id' => '5', 'Bom _ id' => NULL, 'Oe _ production_id '=> NULL, 'note' => 'ld ', 'curr _ id' => '000000', 'Oe _ ean13' => NULL, 'workcenter _ id' => NULL,), 5 => array ('id' => '123', 'create _ uid' => '123 ', 'create _ date' => '2017-01-30 15:38:50. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 15:38:50. 000 ', 'name' => 'c # Advanced Programming', 'Plan _ type' => '000000', 'parent _ id' => '0 ', 'Date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', 'product _ qty' => '1', 'Plan _ ctor '=> '', 'status' => '1', 'routing _ id' => '000000', 'Bom _ id' => '1 ', 'Oe _ production_id '=> '0', 'note' => '', 'curr _ id' => NULL, 'Oe _ ean13' => '123 ', 'workcenter _ id' => NULL, 'ischild '=> 1, 'Plan _ director_name' => '', 0 => array (0 => array ('id' => '000000', 'create _ uid' => '000000 ', 'create _ date' => '2017-01-30 15:38:50. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 15:38:50. 000 ', 'name' => 'c # Advanced Programming _ Times package 1', 'Plan _ type' => '123 ', 'parent _ id' => '000000', 'date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', 'product _ qty' => NULL, 'Plan _ ctor '=> '', 'status' => '3', 'routing _ id' => '6', 'Bom _ id' => NULL, 'Oe _ production_id '=> NULL, 'note' => '', 'curr _ id' => NULL, 'Oe _ ean13 '=> NULL, 'workcenter _ id' => NULL ,), 1 => array ('id' => '000000', 'create _ uid' => '000000', 'create _ date' => '2017-01-30 15:38:50. 000', 'Write _ uid' => '000000', 'Write _ date' => '2017-01-30 15:38:50. 000 ', 'name' => 'c # Advanced Programming _ main Package', 'Plan _ type' => '123', 'parent _ id' => '123 ', 'Date _ start' => '2017-01-30 00:00:00. 000 ', 'date _ stop' => '2017-01-30 00:00:00. 000 ', 'product _ id' => '2', // The restricted string of the rich text box is 10000, so some values are deleted ),),),)

When you see this result, you will be dizzy.

If (is_array ($ val) {// checks whether the $ val value is an array. if yes, it goes to the lower-layer traversal.

?? Yes
If (is_array ($ val) judge? Is there another?

Thank you for finding the cause of the error. when you press the data in the background, no subscript is specified. $ monitorList [$ key] [] = query ($ SQL) directly leads to an error in foreground traversal.
Just give a subscript.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.