PHP: Filling in the 'gaps' in an array

Posted by aboved on Stack Overflow See other posts from Stack Overflow or by aboved
Published on 2010-03-31T22:11:54Z Indexed on 2010/03/31 22:13 UTC
Read the original article Hit count: 300

Filed under:
|
|

Hey gurus,

I've got a php array (obtained through checkbox values in a form - as you know checkboxes only show up in the _POST variable when they are not set).

Array
(
    [2] => 0,2
    [3] => 0,3
)

I need a way to 'fill in' the gaps between the range 0-5. So above would look like (filling the empty spaces with '-1'. I tried array_merge() with an array filled with '-1' but that didn't work.

Array
(
    [0] => -1
    [2] => 0,2
    [3] => 0,3
    [4] => -1
    [5] => -1
)

I think I may have gone down the wrong road with the problem I am trying to solve, but I have put too much time into this solution to back out - a feeling I am sure most of you are familiar with(!)

Cheers!

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays