我有一个数组,如下所示:

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 ))

我想打印谁的。我在foreach中使用条件语句,如下所示:
foreach ($t1 as $key => $value) {
        if($value['cust_type'] = 'Corporate')
            {
                print_r($value['trx']);
            }
        echo "<br/>";
    }

但它打印所有trx值,而不是只打印公司值。
请帮帮我,谢谢。

最佳答案

使用

if($value['cust_type'] == 'Corporate')

而不是
if($value['cust_type'] = 'Corporate')

所以最终的结果是
   foreach ($t1 as $key => $value) {
            if($value['cust_type'] == 'Corporate')
                {
                    print_r($value['trx']);
                }
            echo "<br/>";
        }

10-06 03:31