使用 unset 函数从数组中删除元素的 PHP 程序
要使用 unset 函数从数组中删除元素,PHP 代码如下 −
示例
<?php
$my_array = array("Joe", "Ben", "Mary", "Barun", "Sona", "Mona");
unset($my_array[4]);
print_r("After deleting the element, the array is");
print_r ($my_array);
?>输出
After deleting the element, the array isArray ( [0] => Joe [1] => Ben [2] => Mary [3] => Barun [5] => Mona )
上面定义了一个数组,包含多个字符串 −
$my_array = array("Joe", "Ben", "Mary", "Barun", "Sona", "Mona");unset 函数用于指定需要删除的数组中元素的索引。删除元素后,输出/数组将打印在屏幕上 −
unset($my_array[4]);
print_r("After deleting the element, the array is");
print_r ($my_array);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP