note 99111 added to control-structures.foreach

From: Date: Wed, 28 Jul 2010 11:39:01 +0000
Subject: note 99111 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-171185@lists.php.net to get a copy of this message
Foreach can be also used to move around multiple tables. Here is simple example. <?php $table[0][0][0] = 6; $table[0][0][1] = 17; $table[0][0][2] = 12; $table[0][0][3] = 8; $table[0][1][0] = 9; $table[0][1][1] = 13; $table[0][1][2] = 11; $table[0][1][3] = 5; $table[0][2][0] = 1; $table[1][1][0] = 4; $table[1][2][0] = 2; $table[2][4][1] = 1; foreach ($table as $i1 => $n1) foreach ($n1 as $i2 => $n2) foreach ($n2 as $i3 => $n3) printf('$table[%d][%d][%d] = %d;<br>', $i1,$i2,$i3,$n3);?> It gives the result: $test[0][0][0] = 6; $test[0][0][1] = 17; $test[0][0][2] = 12; $test[0][0][3] = 8; $test[0][1][0] = 9; $test[0][1][1] = 13; $test[0][1][2] = 11; $test[0][1][3] = 5; $test[0][2][0] = 1; $test[1][1][0] = 4; $test[1][2][0] = 2; $test[2][4][1] = 1; ---- Server IP: 69.147.83.197 Probable Submitter: 83.16.155.162 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/99111 Del: integrated -- https://master.php.net/note/delete/99111/integrated Del: useless -- https://master.php.net/note/delete/99111/useless Del: bad code -- https://master.php.net/note/delete/99111/bad+code Del: spam -- https://master.php.net/note/delete/99111/spam Del: non-english -- https://master.php.net/note/delete/99111/non-english Del: in docs -- https://master.php.net/note/delete/99111/in+docs Del: other reasons-- https://master.php.net/note/delete/99111 Reject -- https://master.php.net/note/reject/99111 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171185) next »