如何价值和关键推入阵列(PHP) [英] How to push both value and key into array (php)

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

问题描述

看看这个code:

$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天全站免登陆