RE: setting index of array as 1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In that case, you could do this:

$x = 1;
$query = mysql_query("select name from names order by date desc");
while($result = mysql_fetch_array($query))
{
    $all_names[$x] = $result['name'];	
    $x++;
}


-TG

> -----Original Message-----
> From: Afan Pasalic [mailto:afan@xxxxxxxx] 
> Sent: Monday, October 18, 2004 2:33 PM
> Cc: php-general@xxxxxxxxxxxxx
> Subject: Re:  setting index of array as 1
> 
> 
> It's not what I was looking for. Looks like I didn't explain 
> very well :)
> 
> look at this case:
> 
> $query = mysql_query("select name from names order by date desc");
> while($result = mysql_fetch_array($query))
> {
>     $all_names[] = $result['name'];	
> }
> 
> in this case the array $all_names starts with index 0.
> 
> I can't put
> 
>     $all_names[1] = $result['name'];	
> 
> because every next entry will get index 1 and overwrite old 
> one and on 
> the end I'll have an array of just one element :)
> 
> -afan
> 
> 
> Matthew Sims wrote:
> >>when create an array using:
> >>$new_array[] = 'something';
> >>first index of new array is 0
> >>
> >>how can I though set that first index is 1 - except 
> "reorganize" array
> >>after is created?
> >>
> >>thanks
> >>
> >>-afan
> > 
> > 
> > $new_array = array(1 => 'first','second','third');
> > 
> > echo $new_array[1];  <--- Will echo first
> > 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux