添加关联数组项 [英] Add associative array item

查看:69
本文介绍了添加关联数组项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想向数组添加新项,但我希望它是一个关联数组...我该如何做到这一点?

假设我有一个变量$ arrayContainer.
现在我有一个城市的数据,例如"United State" ="UN","Philippines" ="PH",现在我想当我得到值$ arrayContainer ["UN"]时将输出"United State" ...我该如何做到?如果我想添加另一个关联值,又说我决定要添加键"UAE"以显示阿拉伯联合酋长国",该怎么办...我该如何实现呢?

我在想这样

 $ array [" ] = array('  cebu' => '  c' davao' => '  d'' ' ' ' '  radio' => '  r',$ array ["  span>]);
 echo  $ array [" ] [" ]; 




预先感谢伙计们

解决方案

arrayContainer.
现在,我有一个城市的数据,例如"United State" ="UN","Philippines" ="PH",现在我想要何时获取值

arrayContainer ["UN"]这将输出美国" ...我该如何完成?如果我想添加另一个关联值,又说我决定要添加键"UAE"以显示阿拉伯联合酋长国",该怎么办...我该如何实现呢?

我在想这样

 


array [" "span>] = array(' cebu' => ' c'' davao' => ' d'' 马尼拉' => ' m'' 三宝颜' => ' z'); array_push(' radio' => ' r'


Hi guys i would like to add a new item to an array but i want it to be an associative array... how do i accomplish this?

Let say i have a variable $arrayContainer.
Now i have a data of cities like "United State" = "UN", "Philippines" = "PH", now i want when i get the value $arrayContainer["UN"] this will output "United State"... how do i accomplish that? and also what if i would like to add another associative value let say i decided that i want to add the key "UAE" to display "United Arab Emirates"... How do i accomplish this?

I was thinking like this

$array["city"] = array('cebu' => 'c', 'davao' => 'd', 'manila' => 'm', 'zamboanga' => 'z');

array_push('radio' => 'r',$array["city"] );
echo $array["city"]["radio"];




Thanks in advance guys

解决方案

arrayContainer.
Now i have a data of cities like "United State" = "UN", "Philippines" = "PH", now i want when i get the value


arrayContainer["UN"] this will output "United State"... how do i accomplish that? and also what if i would like to add another associative value let say i decided that i want to add the key "UAE" to display "United Arab Emirates"... How do i accomplish this?

I was thinking like this


array["city"] = array('cebu' => 'c', 'davao' => 'd', 'manila' => 'm', 'zamboanga' => 'z'); array_push('radio' => 'r',


这篇关于添加关联数组项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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