I have out put like below
[0]
{
[0]=>'a'
[2]=>'b'
[5]=>'c'
[6]=>'d'
}
No What i want is to insert un-created array index and set their values to ‘0’.
e.g: in this case i want output like below instead of the one above. can any one show me a sample of code please…………. i tried to use array_fill() but didn’t work it just inserts array index at end.
array_fill($b1, 1, "0");
Desired Output:
[0]
{
[0]=>'a'
[1]=>'0'
[2]=>'b'
[3]=>'0'
[4]=>'0'
[5]=>'c'
[6]=>'d'
}
Cycle through your array, watching the keys. Anytime the last iteration is more than 1 from the current key, perform a short while loop to catch up the array contents.
The output is:
Demo: http://codepad.org/9EnowzqL