PHP array array value with specific condition
i has an array $t1
as shown below:
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 ))
I want to print TRX
whose cust_type = Corporate
. I am using conditional expression inside foreach as shown below:
foreach ($t1 as $key => $value) {
if($value['cust_type'] = 'Corporate')
{
print_r($value['trx']);
}
echo "<br/>";
}
But it prints all TRX values ββinstead of the corporate one. Please help me, thanks.
+3
source to share
2 answers