如何将值和键都推入PHP数组 [英] How to push both value and key into PHP array

查看:72
本文介绍了如何将值和键都推入PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看下面的代码:

$GET = array();    
$key = 'one=1';
$rule = explode('=', $key);
/* array_push($GET, $rule[0] => $rule[1]); */

我正在寻找这样的东西:

I'm looking for something like this so that:

print_r($GET);
/* output: $GET[one => 1, two => 2, ...] */

是否有执行此操作的功能? (因为array_push不能这样工作)

Is there a function to do this? (because array_push won't work this way)

推荐答案

不,对于关联数组,没有array_push()等效项,因为无法确定下一个键.

Nope, there is no array_push() equivalent for associative arrays because there is no way determine the next key.

您必须使用

$arrayname[indexname] = $value;

这篇关于如何将值和键都推入PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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