-1

I get data php sql after i print from json its but i want dont print a item in "" i want dont print id in ""

require('config.php');

$sql="SELECT * FROM file";
$result=$conn->query($sql);

foreach($result as $rows){

    $recordfil=array();
    $recordfil['id']=$rows['idfile'];
    // $recordfil['file']=$rows['filef'];

    $nnfile[]=$recordfil;
}

$filegen=$nnfile;

$arrayovp=[
    'ovpn_file'=>
    $filegen
];

echo json_encode($arrayovp);
?>

It output :

{"ovpn_file":[{"id":"36"},{"id":"35"}]}

I want only 36 or 35 without ""

atlicode
  • 37
  • 7

1 Answers1

0

PHP supports automatically encoding numeric strings as numbers using the JSON_NUMERIC_CHECK option, which might be easier than explicitly type-casting all relevant fields.

Try

echo json_encode($arrayovp, JSON_NUMERIC_CHECK);

# {"ovpn_file":[{"id":36},{"id":35}]}

Demo here: https://3v4l.org/ANdUM

iainn
  • 16,826
  • 9
  • 33
  • 40