我有一个数组跟随
[0] => Array
(
[month] => Oct
[amount] => 1200.00
)
如何通过[amount]
[month]
答案 0 :(得分:6)
你没有。两个选项:
循环:
foreach ($array as $i) {
if ($i['month'] == 'Oct') {
echo $i['amount'];
}
}
按月索引数据:
$array = array_combine(array_map(function($i) { return $i['month']; }, $array),
$array);
echo $array['Oct']['amount'];
答案 1 :(得分:1)
foreach ($arr as $k => $v) {
if ($v['month'] == $needleMonth) {
echo $v['amount'] . ' - that`s it';
break;
}
}
答案 2 :(得分:0)
你必须循环你的数组并每次测试你想要的月份== $ arrayElement [$ i] ['month']
答案 3 :(得分:0)
foreach ($arr as $k=>$v) {
if ($v['month']=='Oct') {
echo $v['amount'];
}
}
答案 4 :(得分:0)
$selectedMonth = 'Oct';
foreach($yourArray as $child){
if($child['month'] == $selectedMonth){
echo $child['amount'];
}
}