php 从php数组中删除行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4727350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 14:09:47  来源:igfitidea点击:

Delete row from php array

phparrays

提问by ensnare

How can I remove an element from an array?

如何从数组中删除元素?

For example:

例如:

$data = Array('first' , 'second' , 'third');
array_delete($data[2]);

#$data would now read Array('first', 'second')

Does such a built-in function exist? Thanks.

这样的内置函数存在吗?谢谢。

回答by alfred

yes. i would have made it shorter, but need at least 30- charcters. so here you go:

是的。我会缩短它,但至少需要 30 个字符。所以你走吧:

unset($data[2]);

回答by Angel.King.47

The above answers work. But here is what i got from the site listed below. I think its cool.

以上答案有效。但这是我从下面列出的网站上得到的。我觉得很酷。

//deletes a number on index $idx in array and returns the new array  
function array_delete($idx,$array) {  
    unset($array[$idx]);  
    return (is_array($array)) ? array_values($array) : null;  
}

http://dev.kafol.net/2009/02/php-array-delete.html

http://dev.kafol.net/2009/02/php-array-delete.html

回答by dqhendricks

unset($data[2]);

yes it does. unset().

是的,它确实。未设置()。