You are here: Re: modifying an array « PHP Programming Language « IT news, forums, messages
Re: modifying an array

Posted by fssm2666 on 08/07/07 15:48

On Aug 6, 9:54 am, zebul0n <zebu...@free.fr> wrote:
> Hello,
>
> I have an array :
>
> Array ( '2' => '27584.10', '3' => '1008.00', '6' => 11393.55, '7' => 888.12 )
>
> which i need to modify to fill missing keys from 0 to 11 with zero
> value. Like this :
>
> Array ( '0' => '0', '1' => '0', '2' => '27584.10', '3' => 1008.00', '4' =>
> '0', '5' => '0', '6' => '11393.55', '7' => '888.12', '8' => '0', '9' =>
> '0', '10' => '0', '11' => '0' )
>
> but I couldn't find an array function to fill the missing keys with a zero
> value.
>
> Thank you.



Hello....

In that case, you are using a statement that create an Associative
Array. This means that every key is an string. Maybe you must change
and define the id as integer without the ' ($array[1]=value).

Ok. Now, you can take some different way: create the array filled woth
zero, and later change the values. Check on the PHP manual the
information about array_fill() function.

(If you want to iterate an array, use: while(list($a,
$b)=each($array)), where you can verify every position in the $array,
$a is the key and $b is the value)

Bye.

Felipe Silva. Chile.

 

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

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