PHP: Reordenar matrizes após unset ()
Existem 2 funções envolvidas.
Pesquisar itens de matriz para uma determinada sequênciaitem de matriz unset () se a sequência não for encontrada$array = array("first", "second", "third", "fourth");
foreach($array as $i=> $string) {
if(stristr($string, "e")) {
unset($array[$i]);
}
}
second
é o item da matriz com o caractere 'e'. Se éunset
, $array[1]
ficaria vazio:
$array[0] = "first"
$array[1] = ""
$array[2] = "third"
$array[3] = "fourth"
eu quero$array[1]
para ser removido da matriz (como emarray_shift()
), de modo athird
toma o lugar desecond
efourth
o lugar dethird
:
$array[0] = "first"
$array[1] = "third"
$array[2] = "fourth"