我有一个数组跟随
[0] => Array
(
[month] => Oct
[amount] => 1200.00
)
以及我如何[amount]
通过[month]
你没有。两种选择:
环形:
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'];
foreach ($arr as $k => $v) {
if ($v['month'] == $needleMonth) {
echo $v['amount'] . ' - that`s it';
break;
}
}
$selectedMonth = 'Oct';
foreach($yourArray as $child){
if($child['month'] == $selectedMonth){
echo $child['amount'];
}
}
如果您想要的月份 == $arrayElement[$i]['month'],您必须循环您的数组并每次测试
foreach ($arr as $k=>$v) {
if ($v['month']=='Oct') {
echo $v['amount'];
}
}