note 33865 modified in function.array by vrana

From: Date: Tue, 17 Aug 2004 13:56:44 +0000
Subject: note 33865 modified in function.array by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80008@lists.php.net to get a copy of this message
I found a slightly better way to create large 2d arrays: <?php // this will simply output a 2d array-- it isn't very robust but it //suits my needs here function display_all($array){ echo "<table><tr>"; foreach($array as $spot){ echo "<td align='center' width= '20'>"; foreach($spot as $spotdeux){ echo "<br>".$spotdeux; } } echo "</tr> </table>"; } //this actually creates the array and puts the value 0 in all // locations. the $xax and $yax can be upped or //downed to create a larger or smaller array function creater_array(){ $ar=Array(); $xax=5; $yax=5; $i=1; for ($y=0; $y<$yax; $y++) { array_push($ar,array()); for ($x=0; $x<$xax; $x++) { array_push($ar[$y],"0"); } } return $ar; } $b = creater_array(); display_all($b); ?> --was-- I found a slightly better way to create large 2d arrays: // this will simply output a 2d array-- it isn't very robust but it //suits my needs here function display_all($array){ echo "<table><tr>"; foreach($array as $spot){ echo "<td align='center' width= '20'>"; foreach($spot as $spotdeux){ echo "<br>".$spotdeux; } } echo "</tr> </table>"; } //this actually creates the array and puts the value 0 in all // locations. the $xax and $yax can be upped or //downed to create a larger or smaller array function creater_array(){ $ar=Array(); $xax=5; $yax=5; $i=1; for ($y=0; $y<$yax; $y++) { array_push($ar,array()); for ($x=0; $x<$xax; $x++) { array_push($ar[$y],"0"); } } return $ar; } $b = creater_array(); display_all($b); http://php.net/manual/en/function.array.php

« previous php.notes (#80008) next »