PHP程序使用unset函数从数组中删除元素
要使用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);热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿