douchen4915
2011-01-22 16:52
浏览 44
已采纳

在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?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • duanhuangyun3887 2011-01-22 16:54
    已采纳

    Use array_keys.

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

    Hope this helps.

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(5条)

相关推荐 更多相似问题