note 46397 deleted from function.each by aidan

From: Date: Sun, 10 Oct 2004 02:05:58 +0000
Subject: note 46397 deleted from function.each by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78257@lists.php.net to get a copy of this message
Note Submitter: boris at example dot com ---- // CAUTION with function EACH and LIST // you get each row in the order you entered it AND // NOT in the order // it´s logical supposed to be. Try //$test_array[0][1]= "Value in 01"; //$test_array[0][0]= "Value in 00"; //$test_array[1][0]= "Value in 10"; //$test_array[1][1]= "Value in 11"; // and you will get a table with: // +-------------+-------------+ // | Value in 01 | Value in 00 | // +-------------+-------------+ // | Value in 10 | Value in 11 | // +-------------+-------------+ // // AND NOT as you might expect: // +-------------+-------------+ // | Value in 00 | Value in 01 | // +-------------+-------------+ // | Value in 10 | Value in 11 | // +-------------+-------------+ TEST CODE: $rows = count( $array ); echo "<table border='1'>"; for ( $i=0; $i<$rows; $i++ ) { list ($key, $val) = each ($array); if ( is_array( $val ) ) { echo "<tr nowrap>"; while (list ($key, $val2) = each ($val)) { if ( !is_array( $val2 ) ) // recursion end { echo "<td nowrap>$val2</td>"; } } echo "</tr>"; } } echo "</table>";

« previous php.notes (#78257) next »