Re: Problems with PHP4 & arrays

From: Date: Tue, 06 Jun 2000 13:16:46 +0000
Subject: Re: Problems with PHP4 & arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-1129@lists.php.net to get a copy of this message
This also works: <? $TIT[0]=5; $TIT[1]=3; $TIT[2]=6; $TIT[4]=9; $TIT[7]=2; for ($i=0; $i<sizeof($TIT); $i++) { if(!isset($TIT[$i])){ $TIT[$i]=" "; } echo $i." - ".$TIT[$i]."<br>\n"; } ?> ----- Original Message ----- From: "Andrea Busia" <busia@tiscalinet.it> To: <php-general@lists.php.net> Sent: Tuesday, June 06, 2000 9:09 AM Subject: [PHP-GENERAL] Problems with PHP4 & arrays > I have written this little Script: > > <? > $TIT[0]=5; > $TIT[1]=3; > $TIT[2]=6; > $TIT[4]=9; > $TIT[7]=2; > for ($i=0; $i<sizeof($TIT); $i++) { > echo $i." - ".$TIT[$i]."<br>\n"; > } > ?> > > if I run it, the output is: > > 0 - 5<br> > 1 - 3<br> > 2 - 6<br> > 3 - <br> > 4 - 9<br> > > But i'd like to have something like this: > > 0 - 5<br> > 1 - 3<br> > 2 - 6<br> > 3 - <br> > 4 - 9<br> > 5 - <br> > 6 - <br> > 7 - 2<br> > > Why the program doesn't output all values (from 0 to 7)? Why it doesn't set > all not defined values to "". I don't knw how many values need before > running the script, I'd like that the array have all values defined before > the last not null (in this case $TIT[7]), in Perl the problem there isn't, > in PHP yes. > > Please help me > > Thanks > Andrea Busia > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#1129) next »