在我下面的代码中,GST和金额打印正确,但折扣 不打印结果。为什么不打印折扣?我该如何解决这个问题?
$GST = Array ( [0] => 18 );
$Amount = Array ( [0] => 25000 );
$Discount = Array ( [0] => 10 );
array_map(
function($GST, $Amount, $Discount){
echo ' GST: '.$GST.' Amount: '.$Amount.' Discount: '.$Discount.'<br>';
echo 'Discount: '.(($Amount * $Discount) / 100).' Amount After Discount: '.($Amount - (($Amount * $Discount) / 100)).'<br>';
echo 'GST: '.(($Amount - (($Amount * $Discount) / 100)) * $GST / 100).'<br>';
//return ($Amount - (($Amount * $Discount) / 100)) * $GST / 100;
},
!is_array($GST) ? [] : $GST,
!is_array($Amount) ? [] : $Amount,
!is_array($Discount) ? [] : $Discount
)
最佳答案
只要重新定义数组,您就应该走上成功之路。用户提供的代码Magnus Eriksson .
$GST = Array (18);
$Amount = Array (25000);
$Discount = Array (10);
array_map(
function($GST, $Amount, $Discount){
var_dump($GST, $Amount, $Discount);
echo PHP_EOL;
echo 'GST: '.$GST.' Amount: '.$Amount.' Discount: '.$Discount.PHP_EOL;
echo 'Discount: '.(($Amount * $Discount) / 100).' Amount After Discount: '.($Amount - (($Amount * $Discount) / 100)).PHP_EOL;
echo 'GST: '.(($Amount - (($Amount * $Discount) / 100)) * $GST / 100).PHP_EOL;
//return ($Amount - (($Amount * $Discount) / 100)) * $GST / 100;
},
!is_array($GST) ? [] : $GST,
!is_array($Amount) ? [] : $Amount,
!is_array($Discount) ? [] : $Discount
);
输出:
int(18)
int(25000)
int(10)
GST: 18 Amount: 25000 Discount: 10
Discount: 2500 Amount After Discount: 22500
GST: 4050
关于PHP array_map 多个参数不起作用 如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53895193/