如何向数组添加值? [英] How to add values to an array ?

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

问题描述

情况如下:



我有2个阵列:



Here's the situation:

I have 2 arrays:

Array(
    [0] => Person1
    [1] => Person1
    [2] => Person3
)

< br $> b $ b



Array(
    [0] => 100.00
    [1] => 150.25
    [2] => 157.15
)





现在,我的问题是:如何从中添加数组值第二个数组,因为它们属于第一个数组中的Person 1?它应输出如下:





Now, my question is: How do I add array values from the second array, as they belong to Person 1 in the first array ? It should output like this:

Array(
    [0] => 250.25 // for Person1 in the first array
    [1] => 157.15 // for Person2 in the first array
)





我找不到任何解决方案..请帮助我。请。



I am not finding any solution for it.. Kindly help me out. Please.

推荐答案

它不能以这种方式工作。实际上,阵列之间没有关系。相反,您应该使用关联数组 [ ^ ],这是一种由名称 - 值对组成的数组。参见示例:

It cannot work this way. As it is, there is no relationship between the arrays. Instead, you should use associative array[^], which is a type of array consisting of name-value pairs. see example:
<?php


first = array( Person1 => 250.25 Person2 => 157.15);
first = array("Person1"=>"250.25", "Person2"=>"157.15");


second = array( Person1 => 100.00);

foreach(
second = array("Person1"=>"100.00"); foreach(


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

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