如何删除阵列键preFIX [英] How to remove prefix in array keys

查看:165
本文介绍了如何删除阵列键preFIX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试删除阵列密钥的preFIX而每一次尝试失败。我想实现的是:

I try to remove a prefix in array keys and every attempt is failing. What I want to achieve is to:

有:阵列([attr_Size] => 3 [attr_Colour] =大于7)

要获取:阵列([尺寸] => 3 [颜色] =大于7)

您帮助将非常AP preciated ...

Your help will be much appreciated...

推荐答案

其中一个方式来获得:阵列([尺寸] => 3 [颜色] => 7)从你的有:阵列([attr_Size] => 3 [attr_Colour] =大于7)

One of the ways To Get:Array ( [Size] => 3 [Colour] => 7 ) From your Having: Array ( [attr_Size] => 3 [attr_Colour] => 7 )

$new_arr = array();
foreach($Your_arr as $key => $value) {

list($dummy, $newkey) = explode('_', $key);
$new_arr[$newkey] = $value;

}

如果您认为会在键选择多个下划线只需更换里面的foreach第一行列表($假人,$则newkey)=爆炸('attr_',$键);

If you think there'll be multiple underscores in keys just replace first line inside foreach with list($dummy, $newkey) = explode('attr_', $key);

这篇关于如何删除阵列键preFIX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆