PHP数组打印特定条件的值


PHP array print value with specific condition

我有一个像下面这样的数组$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 ))

我想打印TRXcust_type = Corporate。我在foreach中使用条件语句,如下所示:

foreach ($t1 as $key => $value) {
        if($value['cust_type'] = 'Corporate')
            {
                print_r($value['trx']);
            }
        echo "<br/>";
    }

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

use

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/>";
        }

用双==代替if($value['cust_type'] == 'Corporate')中的单=