Home > php教程 > php手册 > php数组值增加删除查找操作方法详解

php数组值增加删除查找操作方法详解

WBOY
Release: 2016-06-06 20:09:46
Original
1171 people have browsed it

在php数组中分为数组值与数组key,下面小编来给大家总结一下在php中数组值常用的操作方法包括有:数组中加入数值、判断 数组中的数值、删除特定数组值等有需要的相关php教程的同学可以参考。php爱好者专业分享开发心得 php删除特定数组值 var_dump($context['

在php数组中分为数组值与数组key,下面小编来给大家总结一下在php中数组值常用的操作方法包括有:数组中加入数值、判断 数组中的数值、删除特定数组值等有需要的相关php教程的同学可以参考。php爱好者专业分享开发心得

php删除特定数组值

var_dump($context['linktree']);

得到了

array(3) {
[0]=>
array(2) {
["url"]=>
string(52) “http://127.0.0.1/testforum.cityofsteam.com/index.php”
["name"]=>
string(28) “City of Steam Official Forum”
}
[1]=>
array(2) {
["url"]=>
string(55) “http://127.0.0.1/testforum.cityofsteam.com/index.php#c1″
["name"]=>
string(28) “City of Steam Official Forum”
}
[2]=>
array(2) {
["url"]=>
string(62) “http://127.0.0.1/testforum.cityofsteam.com/index.php?board=4.0″
["name"]=>
string(12) “Announcement”
}
}

我要去掉中间那个。

用:unset($context['linktree']['1']);

array(2) {
[0]=>
array(2) {
["url"]=>
string(52) “http://127.0.0.1/testforum.cityofsteam.com/index.php”
["name"]=>
string(28) “City of Steam Official Forum”
}
[2]=>
array(2) {
["url"]=>
string(62) “http://127.0.0.1/testforum.cityofsteam.com/index.php?board=4.0″
["name"]=>
string(12) “Announcement”
}
}

就少了一个[1]

让这中间的1自动编号:

Array ( [0] => apple [1] => banana [3] => dog )

function array_remove(&$arr, $offset)

{

array_splice($arr, $offset, 1);

}

$arr = array('apple','banana','cat','dog');

array_remove($arr, 2);

print_r($arr);

?>

经过测试可以知道,2的位置这个元素被真正的删除了,并且重新建立了索引。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template