função PHP array_unshift ()
PHP completa matriz de referência
Exemplos
Insira Elemento "azul" para a matriz:
<?php
$a=array("a"=>"red","b"=>"green");
array_unshift($a,"blue");
print_r($a);
?>
$a=array("a"=>"red","b"=>"green");
array_unshift($a,"blue");
print_r($a);
?>
Correndo instância »
Definição e Uso
função array_unshift () é usado para inserir novos elementos na matriz. Valor da nova matriz vai ser inserido no início da matriz.
Dica: Você pode inserir um ou mais valores.
Nota: O valor nome da chave de 0 a 1 incrementos.chaves de string permanecerá inalterada.
gramática
array_unshift( array,value1,value2,value3... )
参数 | 描述 |
---|---|
array | 必需。规定数组。 |
value1 | 必需。规定插入的值。 |
value2 | 可选。规定插入的值。 |
value3 | 可选。规定插入的值。 |
detalhes técnicos
retorna: | Retorna o número de novos elementos na matriz. |
---|---|
versão do PHP: | 4+ |
mais exemplos
exemplo 1
Mostrar o valor de retorno:
<?php
$a=array("a"=>"red","b"=>"green");
print_r(array_unshift($a,"blue"));
?>
$a=array("a"=>"red","b"=>"green");
print_r(array_unshift($a,"blue"));
?>
Correndo instância »
exemplo 2
Usando as teclas numéricas:
<?php
$a=array(0=>"red",1=>"green");
array_unshift($a,"blue");
print_r($a);
?>
$a=array(0=>"red",1=>"green");
array_unshift($a,"blue");
print_r($a);
?>
Correndo instância »
PHP completa matriz de referência