0
I have the following question, for example
<?php
$cesta = array("laranja", "banana", "melancia", "morango");
$fruta = array_pop($cesta);
print_r($cesta);
?>
the array initial goes from position 0 to 3, when I do array_pop
it is from position 0 to 2, but if I add a new element the positions of the array shall be, (0,1,2,4). There is some way to put the positions as (0,1,2,3) excluding one element and then adding another one?
How did you insert the new element? I tested with
$cesta[] = "maçã"
andarray_push($cesta, "maçã")
and in both cases "apple" was inserted in index 3.– Woss
Seriously? to inserting directly with $basket[]="apple"
– Matheus Lima
And how did you conclude that you were inserted in Index 4?
– Woss
To reinforce the @Andersoncarloswoss comment see the test: http://ideone.com/PgiTwi
– rray
This is just an example you have on php.net, in my case I conclude because when I print_r(array), from Indice 7 it jumps to 12.
– Matheus Lima
Can you put that code in the question?
– Woss
The problem is when vc removes a middle element from the array and breaks the Indice sequence?
– rray
I think I identified the problem, I put a global variable to indicate the position of the array but it was not setting its value
– Matheus Lima