我正在测试此代码,因为我想从两个不同的变量($ total和$ currentcy)中获取& published_data ['sample']的值。任何人都可以给我一个如何做到这一点的线索?我一直在阅读它并测试一些代码,但没有!根据此代码,输出为 1000€
这是我的代码:
$currency = '€';
$wedding_budget = '2000,00';
if(trim(strlen($wedding_budget)) >= '6') {
$wedding_budget = preg_replace('/[\.,]/', '', $wedding_budget );
} else {
$wedding_budget = preg_replace('/\.[0-9]{1,2}$/', '', $wedding_budget);
}
$total = $wedding_budget / 2;
$posted_data['sample'] = compact('total', 'currency');
echo $posted_data['sample'];
答案 0 :(得分:0)
这将以更简单的方式实现您想要的目标
$currency = '€';
$wedding_budget = '2000,00';
$wedding_budget = str_replace(',', '.', $wedding_budget);
$total = $wedding_budget / 2;
$posted_data['sample'] = $total . $currency;
echo $posted_data['sample'];
答案 1 :(得分:0)
$ posted_data ['样品'];是一个数组。您可以通过以下方式打印:
echo $posted_data['sample']['total'];
echo $posted_data['sample']['currency'];
此致