|
Posted by gosha bine on 08/06/07 14:44
On 06.08.2007 15:54 zebul0n 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.
try
$b = $a + array_fill(0, 12, 0);
ksort($b);
print_r($b);
I'm curious why you need this.
--
gosha bine
makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Navigation:
[Reply to this message]
|