博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php unset函数_PHP | 使用unset()函数从数组中删除元素
阅读量:2529 次
发布时间:2019-05-11

本文共 1407 字,大约阅读时间需要 4 分钟。

php unset函数

Given an array and we have to remove an element from the array.

给定一个数组,我们必须从数组中删除一个元素。

unset()函数 (unset() function)

To remove an element from an array, we can use a PHP library unset() function, it accepts the index and removes the element exists on the specified index.

要从数组中删除元素 ,我们可以使用PHP库unset()函数 ,该函数接受索引并删除指定索引上存在的元素。

We are also using another function var_dump() – which dumps the variable details i.e. here, it will print the array variable.

我们还使用了另一个函数var_dump() -转储变量的详细信息,即在这里,它将打印数组变量。

PHP code to remove an element from an array

PHP代码从数组中删除元素

Output

输出量

array(4) {  [0]=>  string(3) "the"  [1]=>  string(5) "quick"    [2]=>  string(5) "brown"    [3]=>  string(3) "fox" }array(3) {  [0]=>  string(3) "the"   [2]=>  string(5) "brown"    [3]=>  string(3) "fox" }array(3) {  [0]=>  string(3) "the"   [1]=>  string(5) "brown"    [2]=>  string(3) "fox" }

Explanation:

说明:

Here, We've created an array ($array) and then used the PHP unset() method to remove index 1 (which is the 2nd value since array starts from 0). Once that's removed, we print the array using var_dump but there is a problem that the indexes haven't updated. So, we create $array_new by using array_values() method on the existing $array.

在这里,我们创建了一个数组( $ array ),然后使用PHP unset()方法删除了索引1(这是第二个值,因为array从0开始)。 删除后,我们使用var_dump打印数组,但是存在索引尚未更新的问题。 因此,我们通过在现有$ array上使用array_values()方法创建$ array_new 。

翻译自:

php unset函数

转载地址:http://bctzd.baihongyu.com/

你可能感兴趣的文章
CentOS7 重置root密码
查看>>
Centos安装Python3
查看>>
PHP批量插入
查看>>
laravel连接sql server 2008
查看>>
Laravel框架学习笔记之任务调度(定时任务)
查看>>
Ubuntu菜鸟入门(五)—— 一些编程相关工具
查看>>
valgrind检测linux程序内存泄露
查看>>
Hadoop以及组件介绍
查看>>
1020 Tree Traversals (25)(25 point(s))
查看>>
第一次作业
查看>>
“==”运算符与equals()
查看>>
单工、半双工和全双工的定义
查看>>
Hdu【线段树】基础题.cpp
查看>>
时钟系统
查看>>
BiTree
查看>>
5个基于HTML5的加载动画推荐
查看>>
水平权限漏洞的修复方案
查看>>
静态链接与动态链接的区别
查看>>
Android 关于悬浮窗权限的问题
查看>>
如何使用mysql
查看>>