array_push_PHP array_push()函数与示例
array_push
PHP array_push()函數(shù) (PHP array_push() function)
array_push() function is used to insert/push one or more than one element to the array.
array_push()函數(shù)用于將一個(gè)或多個(gè)元素插入/推入數(shù)組。
Syntax:
句法:
array_push(array, elemement1, [element2],..);Here,
這里,
array is the source array in which we have to push the elements.
array是我們必須在其中推送元素的源數(shù)組。
element is the value to be added, we can add more than one elements too.
element是要添加的值,我們也可以添加多個(gè)元素。
Examples:
例子:
Input://initial array is$arr = array(100, 200, 300);//pushing elementsarray_push($arr, 10);array_push($arr, 400, 500);Output:Array( [0] => 100[1] => 200[2] => 300[3] => 10 [4] => 400[5] => 500)PHP code 1: Inserting elements in an indexed array
PHP代碼1:在索引數(shù)組中插入元素
<?php$arr = array(100, 200, 300);array_push($arr, 10);array_push($arr, 400, 500);print("array after inserting elements...\n");print_r($arr); ?>Output
輸出量
random key: age array of random keys... Array ( [0] => age [1] => city )PHP code 2: Inserting elements in an associative array
PHP代碼2:在關(guān)聯(lián)數(shù)組中插入元素
<?php$arr = array("name" => "Amit", "age" => 21);array_push($arr, "Gwalior");array_push($arr, "Male", "RGTU University");print("array after inserting elements...\n");print_r($arr); ?>Output
輸出量
array after inserting elements... Array ( [name] => Amit[age] => 21[0] => Gwalior[1] => Male[2] => RGTU University )See the output – There are two keys name and age and we added three more elements "Gwalior", "Male" and "RGTU University", these three elements added with the keys 0, 1 and 2.
看到輸出-有兩個(gè)關(guān)鍵的姓名和年齡 ,我們?cè)黾恿巳齻€(gè)要素“瓜廖爾”,“ 男性”和“RGTU大學(xué)”,與鍵0,1和2添加了這三個(gè)要素。
翻譯自: https://www.includehelp.com/php/array_push-function-with-example.aspx
array_push
總結(jié)
以上是生活随笔為你收集整理的array_push_PHP array_push()函数与示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网络安全 攻击类型_网络攻击的类型| 网
- 下一篇: array_fill_PHP array