【发布时间】:2015-09-28 16:22:12
【问题描述】:
我有一个数组$t1,如下所示:
Array (
[0] => Array (
[cust_type] => Corporate
[trx] => 1
[amount] => 10 )
[1] => Array (
[cust_type] => Non Corporate
[trx] => 2
[amount] => 20 )
[2] => Array (
[cust_type] => Corporate
[trx] => 3
[amount] => 30 )
[3] => Array (
[cust_type] => Non Corporate
[trx] => 4
[amount] => 40 ))
我想打印TRX 的cust_type = Corporate。我在 foreach 中使用条件语句如下:
foreach ($t1 as $key => $value) {
if($value['cust_type'] = 'Corporate')
{
print_r($value['trx']);
}
echo "<br/>";
}
但它会打印所有 TRX 值而不是仅打印公司值。 请帮助我,谢谢。
【问题讨论】:
标签: php arrays if-statement foreach