|
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]
|