note 46397 added to function.each

From: Date: Sat, 09 Oct 2004 18:20:15 +0000
Subject: note 46397 added to function.each
Groups: php.notes 
Request: Send a blank email to php-notes+get-78236@lists.php.net to get a copy of this message
// 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>"; ---- Manual Page -- http://www.php.net/manual/en/function.each.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46397 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46397&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46397&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78236) next »