array_unshift 在数组开头插入一个或多个单元 &reftitle.description; intarray_unshift arrayarray mixedvalues array_unshift 将传入的单元插入到 array 数组的开头。注意单元是作为整体被插入的,因此传入单元将保持同样的顺序。所有的数值键名将修改为从零开始重新计数,所有的文字键名保持不变。 ¬e.reset-index; &reftitle.parameters; array 输入的数组。 values 插入的变量。 &reftitle.returnvalues; 返回 array 数组新的单元数目。 &reftitle.changelog; &Version; &Description; 7.3.0 现在可以只用一个参数来调用,之前至少需要两个参数。 &reftitle.examples; <function>array_unshift</function> 示例 ]]> &example.outputs; string(5) "apple" [1] => string(9) "raspberry" [2] => string(6) "orange" [3] => string(6) "banana" } ]]> 关联数组用法 如果一个关联数组添加到另一个关联数组开头,则添加到开头的数组将数字索引到前者的数组中。 [ 'McIntosh' => 'red', 'Granny Smith' => 'green', ], 'oranges' => [ 'Navel' => 'orange', 'Valencia' => 'orange', ], ]; $vegetables = [ 'lettuce' => [ 'Iceberg' => 'green', 'Butterhead' => 'green', ], 'carrots' => [ 'Deep Purple Hybrid' => 'purple', 'Imperator' => 'orange', ], 'cucumber' => [ 'Kirby' => 'green', 'Gherkin' => 'green', ], ]; array_unshift($foods, $vegetables); var_dump($foods); ?> ]]> &example.outputs; array(3) { ["lettuce"]=> array(2) { ["Iceberg"]=> string(5) "green" ["Butterhead"]=> string(5) "green" } ["carrots"]=> array(2) { ["Deep Purple Hybrid"]=> string(6) "purple" ["Imperator"]=> string(6) "orange" } ["cucumber"]=> array(2) { ["Kirby"]=> string(5) "green" ["Gherkin"]=> string(5) "green" } } ["apples"]=> array(2) { ["McIntosh"]=> string(3) "red" ["Granny Smith"]=> string(5) "green" } ["oranges"]=> array(2) { ["Navel"]=> string(6) "orange" ["Valencia"]=> string(6) "orange" } } ]]> &reftitle.seealso; array_merge array_shift array_push array_pop