欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

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

程序员文章站 2024-01-19 11:01:58
...

在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的位置这个元素被真正的删除了,并且重新建立了索引。

上一篇: less_html/css_WEB-ITnose

下一篇: php级联