0

My Code Having Json Response Like this

["0","0","0","0","0","0","204.4"]

Need Like This

[ 0, 0, 0, 0, 0, 0, 204.4 ]

For this I have done codeigniter

$query = $this->db->query($selectQuery);
    $totalInvoice = array();
    foreach ($query->result() as $row)
    {
        $totalInvoice[] = $row->total;
    }
    print_r(json_encode($totalInvoice));

This Response is

["0","0","0","0","0","0","204.4"]
Madhuri Patel
  • 1,270
  • 12
  • 24
Vinoth Smart
  • 383
  • 3
  • 13

1 Answers1

1

Add JSON_NUMERIC_CHECK (integer) when encode in json.

JSON_NUMERIC_CHECK (integer) : Encodes numeric strings as numbers

$query = $this->db->query($selectQuery);
    $totalInvoice = array();
    foreach ($query->result() as $row)
    {
        $totalInvoice[] = $row->total;
    }
    print_r(json_encode($totalInvoice, JSON_NUMERIC_CHECK);
Madhuri Patel
  • 1,270
  • 12
  • 24