php删除多维数组的一列,php如何删除多维数组

php如何删除多维数组

php删除多维数组的方法:首先创建一个PHP示例文件;然后通过unsetMultiKeys方法删除复杂的多维数组里面的指定键值对;最后查看运行结果即可。

641202f48e1da8f1079c5799758460d8.png

推荐:《PHP视频教程》

php删除多维数组里面的值

在手册里面发现,改造后变成了一个函数,可以删除复杂的多维数组里面的制定键值对!<?php

$arr = [

'test' => 'value',

'level_one' => [

'level_two' => [

'level_three' => [

'replace_this_array' => [

'special_key' => 'replacement_value',

'key_one' => 'testing',

'key_two' => 'value',

'four' => 'another value',

],

],

'ordinary_key' => 'value',

],

],

];

$unset = array('special_key', 'ordinary_key', 'four');

echo "

";

print_r(unsetMultiKeys($unset, $arr));

print_r($arr);

echo "

";

exit;

function unsetMultiKeys($unset, $array) {

$arrayIterator = new \RecursiveArrayIterator($array);

$recursiveIterator = new \RecursiveIteratorIterator($arrayIterator, \RecursiveIteratorIterator::SELF_FIRST);

foreach ($recursiveIterator as $key => $value) {

foreach ($unset as $v) {

if (is_array($value) && array_key_exists($v, $value)) {

// 删除不要的值

unset($value[$v]);

// Get the current depth and traverse back up the tree, saving the modifications

$currentDepth = $recursiveIterator->getDepth();

for ($subDepth = $currentDepth; $subDepth >= 0; $subDepth--) {

// Get the current level iterator

$subIterator = $recursiveIterator->getSubIterator($subDepth);

// If we are on the level we want to change, use the replacements ($value) other wise set the key to the parent iterators value

$subIterator->offsetSet($subIterator->key(), ($subDepth === $currentDepth ? $value : $recursiveIterator->getSubIterator(($subDepth + 1))->getArrayCopy()));

}

}

}

}

return $recursiveIterator->getArrayCopy();

}

运行结果:

7c3a3e6fd4bbb358d96401dca7175d52.png

改变多维数组里面的键值对

php如何删除多维数组的教程已介绍完毕,更多请关注跳墙网其他文章教程!

php如何删除多维数组相关教程

关于Laradocke运行TP项目

下面由 thinkphp 框架教程栏目给大家介绍关于Laradocke运行TP项目,希望对需要的朋友有所帮助! 一、laradock首次up的时候,build过程非常慢 由于拉取容器的镜像默认在国外,所以在docker-compose up 容器之前,在.env文件中查找以下文字 CHANGE_SOURCE=``fa

如何种植屡获殊荣的青豆

如何种植屡获殊荣的青豆 Most people don’t know this yet, but I’ve decided to give up computers and become a farmer instead. Since I’m the helpful type, I’ve decided to share everything I know about farming with you, starting with how I

CC2530如何实现(1.1uA)低功耗?

CC2530如何实现(1.1uA)低功耗? ?ZigBee网络低功耗运行一直是苦逼攻城狮们要解决的问题,TI的CC2530可以说已经把终端的休眠功耗降低到了极致,现在我们就来体验这颗芯片的魅力! 文章末尾分享完整源码和PCB工程文件。 一、CC2530供电模式 CC2530芯片有五种运

recuva文件恢复乱码_使用Recuva恢复意外删除的文件

recuva文件恢复乱码_使用Recuva恢复意外删除的文件 recuva文件恢复乱码 It can be the worst feeling in the world when you accidentally delete a very important file you have been working on for days. Today we look at Recuva, a free tool that hel

删除Custom aboutconfig即可轻松输入

删除Custom about:config即可轻松输入 Have you ever added a custom about:config entry to your Firefox browser and then wished that you could remove it? Now you can with a simple reset tweak that focuses on singular entries. 您是否曾经在Fire

最新出炉头条三面技术四面HR看我如何一步一步攻克面试官

最新出炉,头条三面技术四面HR,看我如何一步一步攻克面试官? 最开始面的头条游戏中台,当时是第一次面试,没有经验,导致算法题虽然有思路,但是没有写出最优解,直接挂了。后来又被捞起来,因为此时已有阿里的offer,所以胆子也大起来了,收拾心情开始面

popd linux_如何在Linux上使用Push和Popd

popd linux_如何在Linux上使用Push和Popd popd linux Fatmawati Achmad Zaenuri/ShutterstockFatmawati Achmad Zaenuri / Shutterstock Many Linux folks have never heard of pushd and popd , but they’ve been around forever. They can also dramaticall

如何在Linux上使用join命令

如何在Linux上使用join命令 Fatmawati Achmad Zaenuri/ShutterstockFatmawati Achmad Zaenuri / Shutterstock If you want to merge data from two text files by matching a common field, you can use the Linux join command. It adds a sprinkle of dynam

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值