vendredi 16 août 2019

PHP JSON output condition

I need to check if a value is 1 to output some HTML.

Here's part of my json file:

{
    "DeliveryMethods": [
    {
        "id": "delradio",
        "name": "Delivery",
        "on": 0
    },

    {
        "id": "collectRadio",
        "name": "Collection",
        "on": 1
    }]
}

I am creating a radion button with the above, here's also part of the code:

foreach ($out as $del => $method) {
    if($del=="DeliveryMethods"){
    foreach ($method as $delivery) {
?>
<label>
<input type="radio" name="<?php echo $delivery->name;?>" id="<?php echo $delivery->id;?>"><?php echo $delivery->name;?></label>

I want to only create a radion button only for the one if $delivery-> is 1. Sometimes both can be 1 or either/or. Tried putting in a if($delivery->on==1) just after the second foreach but that still outputs both. How can I check or do I need to modify my JSON?

Aucun commentaire:

Enregistrer un commentaire