替换PHP数组的字符串键 [英] Replace string key of PHP array

查看:50
本文介绍了替换PHP数组的字符串键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中有一个看起来像这样的数组:

I have an array in PHP which looks like that:

$test = array('3' => 5);

如何替换字符串数组键3?
我尝试过:

How could I replace the stringed array key 3? I tried:

$test['3'] = "New value"

但它不起作用,之后看起来像这样:

but it don't work, it look like that after that:

array('3' => 5, 3 => "New value")

PHP版本:5.2.11

PHP version: 5.2.11

推荐答案

获取数字索引的最可能方法按字符串表示将具有数字属性名称的对象转换为数组时。

The most possible way you can get the numerical index represented by string is when you convert object with numeric property name to array.

对此进行了更详细的介绍此处

More detailed this covered here

这篇关于替换PHP数组的字符串键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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