|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-02-02 18:58 UTC] yohgaki@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 01:00:01 2025 UTC |
TRUE is represented as 1, FALSE or (boolean)0 ought to be represented as 0, but is actually NULL; This results in numerous side-effects such as HTML-tables partially shown, etc ... <? // // L206.php // include("ukFnctLib.php"); //================================== //sample data for($no=0;$no<5;$no++) { $arrContact[$no]= array ( "surname" =>"surname".$no, "christianName" =>"christianName".$no, "address" =>"address".$no, "country" =>"country".$no, "postcode" =>"postcode".$no, "town" =>"town".$no, "phone" =>"phone".$no, "fax" =>"fax".$no, "email" =>"email".$no, "age" =>20+$no, "height" =>1+$no/10, "nice2" =>(($no%2)==0?"TRUE":"FALSE"), "nice1" =>(($no%2)==0?TRUE:(boolean)NULL) ) ; }//for //================================== //the author's way: foreach foreach($arrContact as $arrContactKey=>$arrAddress) { foreach($arrAddress as $arrAddressKey=>$arrAddressData) { echo $arrContactKey,": ",$arrAddressKey,": ",$arrAddressData,"<br>"; }//foreach echo "<br>"; }//foreach //================================== //uk's way ukPrintTable($arrContact); ?> include: function ukPrintTable($array) { //new table echo"<table border=1>"; //table header echo"<th>array key</th>"; echo"<th>array data type</th>"; echo"<th>array value</th>"; //table rows do { echo"<tr>"; echo"<td>",key($array),"</td>"; echo"<td>"; echo gettype(current($array)); echo"</td>"; echo"<td>"; if(gettype(current($array))=="array") ukPrintTable(current($array)); else echo current($array); echo"</td>"; echo"</tr>"; }while(next($array)); //end of table echo "</table>"; }//uk_print_table