PHP 编程语言的 array_push() 函数实际上是一个内置函数,它有助于根据我们的要求将新元素推送到特定的数组中。我们可以根据需要将一个或多个元素推送到特定数组中,这些数组元素将插入到最后一个节/索引值位置。由于使用 array_push() 函数,特定数组的长度将根据推入特定数组的元素数量而增加/增加。
开始您的免费软件开发课程
网络开发、编程语言、软件测试及其他
语法和参数
PHP array_push() 的语法和参数为:
array_push($array1, $value1, $value2, $value3, …..)
array_push()函数的参数说明:
PHP 编程语言的 array_push() 函数内部将有多个可用参数。 array_push() 函数的参数数量基本上取决于实际推入特定数组的元素数量。具体可以将这些参数分为两类。它们是 1. $array1, 2. 值列表
- array_push() 函数的$array1 参数: array_push() 函数的$array1 参数实际上是实际指定或操作的原始数组。它是主数组,包含之前定义的所有数组元素。
- 值列表(多个值参数):值列表是 PHP 编程语言的 array_push() 函数的多个参数。该参数是一堆实际上用逗号分隔的元素列表,这些分隔的元素将被推入某个特定的数组中。让这些数组为 $value1、$value2、$Value3、$Value4 等等。
- array_push() 函数的返回值: PHP 编程语言的 array_push() 函数只会通过引用的参数值添加/推送一些元素来返回修改后的数组到 array_push() 函数内部。添加的这些元素将根据我们的要求放置在一个/多个数组的最后一个索引值处。
array_push() 函数在 PHP 中如何工作?
PHP 编程语言的 array_push() 函数基本上只是将一些元素推入特定数组。 array_push() 函数还可以将多个元素推送到实际在 array_push() 函数内部指定的原始数组中。使其工作后,数组的长度将增加,并且基于推入数组的元素数量。如果数组具有键和值对,则该方法将尝试将数字键添加到推送的值中。 PHP 的 array_push() 函数仅在 PHP 4、PHP 5 和 PHP 7 版本上运行。
示例#1
这是借助原始数组参数和值列表参数说明 array_push() 函数的示例。首先在 PHP 标签
内部标签用于水平线。之后,在 array() 函数的帮助下使用一些字符串数组索引值/元素创建一个数组变量,但这里的键没有定义。然后原始数组元素将在“print_r()”函数的帮助下打印。然后创建一些值变量并在其中存储一些字符串值。这里创建了六个带有值的字符串变量。然后 array_push() 函数与原始变量和传递给它的所有六个字符串变量一起使用。这会将所有提到的元素推送到特定数组中。然后 print_r($array1) 函数将打印包含所有额外元素的数组。
代码:
<?php // PHP code which helps in illustrating the usage of array_push() function of PHP // The Input array echo "<hr>"; $array1 = array("ram", "krishna", "aakash"); echo "The array values which are present before pushing elements :: "; echo "<br>"; print_r($array1); echo "<hr>"; // elements to push $value1 = "pavan"; $value2 = "kumar"; $value3 = "sake"; $value4 = "anil"; $value5 = "maruthi"; $value6 = "raj"; echo "The array values which are present after using the pushing function :: "; echo "<br>"; // This is the array which is after the pushing of some new elements array_push($array1, $value1, $value2, $value3, $value4, $value5, $value6); print_r($array1); echo "<hr>"; ?>
输出:
示例#2
这个示例与示例 1 类似,但不同之处在于,在 array() 函数内部,声明/提到了 Key 和 value 参数(提到了 Key_value 对)。除此之外,一切都与示例 1 非常相似。您可以检查下面输出部分中提到的程序的输出,以便更好、更轻松地理解 array_push() 函数。
代码:
<?php // PHP code which helps in illustrating the usage of array_push() function of PHP // The Input array echo "<hr>"; $array2 = array(1=>"rahim", 2=>"krishnaveni", 3=>"lion"); echo "The array values which are present before pushing elements :: "; echo "<br>"; print_r($array2); echo "<hr>"; // elements to push $valuea1 = "pavan"; $valuea2 = "sake"; $valuea3 = "kumar"; $valuea4 = "king"; $valuea5 = "queen"; $valuea6 = "birbal"; echo "The array values which are present after using the pushing function :: "; echo "<br>"; // This is the array which is after the pushing of some new elements array_push($array2, $valuea1, $valuea2, $valuea3, $valuea4, $valuea5, $valuea6); print_r($array2); echo "<hr>"; ?>
输出:
Example #3
This example is a simple illustration of the array_push() function but here only some integer values are used as the array elements. Then four variables are created with some integer values to it. Then all those four variable values are pushed into the original array with the help of array_push() function. Other than this everything is similar to example 1 and 2. You can check the output below to understand the concept of array_push() better and so easily.
Code:
<?php // PHP code which helps in illustrating the usage of array_push() function of PHP // The Input array echo "<hr>"; $array2 = array(2, 42, 8); echo "The array values which are present before pushing elements :: "; echo "<br>"; print_r($array2); echo "<hr>"; // elements to push $valuea1 = 12; $valuea2 = 13; $valuea3 = 14; $valuea4 = 15; echo "The array values which are present after using the pushing function :: "; echo "<br>"; // This is the array which is after the pushing of some new elements array_push($array2, $valuea1, $valuea2, $valuea3, $valuea4); print_r($array2); echo "<hr>"; ?>
Output:
以上是PHP array_push()的详细内容。更多信息请关注PHP中文网其他相关文章!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

Atom编辑器mac版下载
最流行的的开源编辑器

Dreamweaver Mac版
视觉化网页开发工具

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。