通过PHP中的整数索引访问关联数组 [英] Accessing an associative array by integer index in PHP

查看:186
本文介绍了通过PHP中的整数索引访问关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用键/值对的数组索引设置关联数组的值.例如:

I want to set the value of an associative array using the array index of the key/value pair. For example:

$my_arr = array( "bling" => "some bling", "bling2" => "lots O bling" );
$my_arr[1] = "not so much bling";  // Would change the value with key bling2.

如何在不使用键串的情况下完成此任务?

How can this be accomplish this without using the key string?

推荐答案

使用 array_keys .

$keys = array_keys($my_arr);
$my_arr[$keys[1]] = "not so much bling";

希望这会有所帮助.

这篇关于通过PHP中的整数索引访问关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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