[Solved] Delete first array php


The only reason why you would get such an output is because you print_r inside the loop.

I believe you have something like:

$aa = [47, 51];

foreach($aa as $a){
    $b[] = $a;
    print_r($b);
}

/*Output:
Array
(
    [0] => 47
)
Array
(
    [0] => 47
    [1] => 51
)*/

But instead you should have done this:

$aa = [47, 51];

foreach($aa as $a){
    $b[] = $a;
}
print_r($b);

/*Output:
Array
(
    [0] => 47
    [1] => 51
)

Here you can see the difference.

First two outputs are from inside the loop, the last is after the loop.

https://3v4l.org/kln74

I.e. your code is correct but the output is placed wrong and therefore confusing you to believe there is two items with key 0 and value 47.

0

solved Delete first array php