You are here: Re: Start array key at 1 « PHP Programming Language « IT news, forums, messages
Re: Start array key at 1

Posted by Shelly on 10/29/07 22:41

"Chris" <matchett123@googlemail.com> wrote in message
news:1193691642.582876.300860@22g2000hsm.googlegroups.com...
> How can I change the following snippet to have the array key start at
> 1 and not 0?
>
> $timetable = explode(',', $row['timetable']);
>
> It is taken from the following code...first time around the loop
> $timetable["$eachperiod"] = $timetable[1] which puts me out of sync
> with the number of fields I am creating ie. I lose $timetable[0].
>
> // Weekdays
> for ($weekdays=0;$weekdays <=4;$weekdays++) {
> echo "<tr>\n";
> $day = array('Mon', 'Tue', 'Wed','Thu','Fri');
> echo "\t<td class=\"tbl_day\">".$day[$weekdays]."</td>\n";
>
> // Periods
> for ($periods=1;$periods <=$num_periods;$periods++) {
> $eachperiod = $weekdays*$num_periods+$periods;
>
> // Fill the table with periods
> $fields = $timetable["$eachperiod"];
>
> Cheers,
>
> Chris

What is your problem? Except for ancient languages like Fortran, arrays
start at 0. Simply rewrite the loop to be:

for ($periods=0;$periods <$num_periods;$periods++) {

Shelly

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация