i have an array $t1 like 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 use conditional statement inside foreach as 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 corporate only. Kindly help me, thank you.
use
if($value['cust_type'] == 'Corporate')
instead of
if($value['cust_type'] = 'Corporate')
So the final result will be
foreach ($t1 as $key => $value) {
if($value['cust_type'] == 'Corporate')
{
print_r($value['trx']);
}
echo "<br/>";
}
Use double == in place of single = in if($value['cust_type'] == 'Corporate')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With