PHP - 使用三元运算符跨越结束标记
PHP - span closing tag in with Ternary Operator
$json = '[{"Number":"333567","Cost":0},{"Number":"333568","Cost":7500},{"Number":"333569","Cost":7500}]';
$options = json_decode($json, true);
foreach ($options as $key => $value) {
$newArray[$value['Number']]= $value['Number']." "."<br /> <span>".($value['Cost'] / 100 == 0 ? 'Free </span>': "£ </span>".$value['Cost'] / 100);
}
echo '<br>';
echo '<br>';
echo json_encode($newArray);
echo '<br>';
我只需要在 Cost 左右添加 span 标签,而且价格不包含 Number
不会呈现结束标记...
我尝试了很多东西,但坚持了这一点:
$newArray[$value['Number']]= $value['Number']." "."<br /> <span>".($value['Cost'] / 100 == 0 ? 'Free' : "£".($value['Cost'] / 100)."</span>");
$newArray[$value['Number']]= $value['Number']." "."<br /> <span>".($value['Cost'] / 100 == 0 ? 'Free' : "£".($value['Cost'] / 100))."</span>";
$json = '[{"Number":"333567","Cost":0},{"Number":"333568","Cost":7500},{"Number":"333569","Cost":7500}]';
$options = json_decode($json, true);
foreach ($options as $key => $value) {
$newArray[$value['Number']]= $value['Number']." "."<br /> <span>".($value['Cost'] / 100 == 0 ? 'Free </span>': "£ </span>".$value['Cost'] / 100);
}
echo '<br>';
echo '<br>';
echo json_encode($newArray);
echo '<br>';
我只需要在 Cost 左右添加 span 标签,而且价格不包含 Number
不会呈现结束标记...
我尝试了很多东西,但坚持了这一点:
$newArray[$value['Number']]= $value['Number']." "."<br /> <span>".($value['Cost'] / 100 == 0 ? 'Free' : "£".($value['Cost'] / 100)."</span>");
$newArray[$value['Number']]= $value['Number']." "."<br /> <span>".($value['Cost'] / 100 == 0 ? 'Free' : "£".($value['Cost'] / 100))."</span>";