The below method have changed property instance in object into array but the requirement have different, the result of response will be same required after manipulation.
<?php
$data = array('statusCode'=>200,
'statusDescripion'=>'success',
'data'=> array('companyImage'=>new StdClass(),
'profile'=>array())
);
echo "<br><br> Encoded data coming from API<br>";
echo $encodeData = json_encode($data,true);
//echo "<br><br> Decode data for Manipulation <br>";
$decodeData = json_decode($encodeData,true);
//print_r($decodeData);
if($decodeData['statusCode'] == 200){
$data_ = array('statusCode'=>$decodeData['statusCode'],
'statusDescripion'=>$decodeData['statusDescripion'],
'data'=>$decodeData['data'],
'url'=>"php.com");
}
echo "<br><br> After Manipulation <br>";
echo json_encode($data_,true);
json_decode
, so you'll either need to change it back manually, or don't pass true, and update the values by accessing properties instead of array key. By the by, what's with thetrue
injson_encode
?