jeudi 5 décembre 2019

How to fix unset json object in php

I have below json object,

{"products":[
{"type":"HR_ECLAIM","name":"HR Claims","is_fixed_price":true,"price":500.5,"currency":"MYR","status":"true"},
{"type":"HR_ELEAVE","name":"HR Leave","is_fixed_price":true,"price":500,"currency":"MYR","status":"false"},
{"type":"FIN_ADVISORY","name":"Finance Advisory","is_fixed_price":false,"currency":"MYR","status":"true"}],
"total_invoices":"100-600","total_staffs":"500-400",
"google_drive_url":"https:\/\/drive.google.com\/open?id=1Is6QsnuMLu9ZIpqeEzR2O2Ve1wUyF92aVCg55kWsOgc","remark":"","status":"pending"}

i want to remove all the products that have status = 'false'

i used below code,

$jsonOutput = $orders->data;
        $json_output = json_decode($jsonOutput, true);
        $products = (isset($json_output['order_info']['products'])?$json_output['order_info']['products']:[]);

        foreach ($products as $hitsIndex => $hitsValue) {

            if ($hitsValue['status'] === 'false') {
                unset($hitsValue);
            }   

        }

        $array1234 = array_values($products);
        json_encode($array1234, true);

but it not working!

Can someone helps me??



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire