$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>';
I need to add span tag only around Cost Free and with price not with Number
Closing tag is wont be rendered...
I tried many things but stuck on this:
$newArray[$value['Number']]= $value['Number']." "."<br /> <span>".($value['Cost'] / 100 == 0 ? 'Free' : "£".($value['Cost'] / 100)."</span>");
CodePudding user response:
$newArray[$value['Number']]= $value['Number']." "."<br /> <span>".($value['Cost'] / 100 == 0 ? 'Free' : "£".($value['Cost'] / 100))."</span>";