php - Replace value of the array when null -
i created webservice in php info mysql db , returns json.
so, need that, whenever have null value
db, value changed white (= " "
).
i did way, without success (look lastly foreach
):
<?php header("content-type: application/json; charset=utf-8;"); include('connectdb.php'); $something = $_get['cod']; $sqlcode = mysql_query("select descricao, cliente, local terminal_cartao descricao='$something'"); $sqlcode2 = mysql_query("select descricao, cliente, local terminal_cartao"); $jsonobj= array(); if($something == 'all') { while($result=mysql_fetch_object($sqlcode2)) { $jsonobj[] = $result; } } else{ while($result=mysql_fetch_object($sqlcode)) { $jsonobj[] = $result; } } foreach ($jsonobj $key => $value) { if ($value === null) { $jsonobj[$key] = ""; } } $final_res =json_encode($jsonobj); echo $final_res; exit;
foreach ($jsonobj $key => $value) { $value = get_object_vars($value); foreach($value $key2 => $value2) { if ($value2 === null) { $jsonobj[$key]->$key2 = ""; } } }
php mysql arrays null
No comments:
Post a Comment