Home > Software engineering >  How to remove quotes from a PHP variable (PHP API)
How to remove quotes from a PHP variable (PHP API)

Time:12-27

I made an API in PHP and un try to remove quotes of my PHP variables.

Here is the code for my API:

  for ($i = 0; $i < 48; $i  = 1) {
        $hourly[$i] =
            array(
                "seeing" => $seeing[$i]),
                "transparency" => $transparency[$i],
                "time" => $timeforapi[$i]
            );
    }

And here is the return of my API:

"hourly": [
    {
        "seeing": "1.2",
        "transparency": "0.5",
        "time": 1672074000
    },

But as you can see there are quotes for seeing and transparency.

I try this to remove it but it doesn't take it away

  "seeing" => str_replace('"', "", $seeing[$i]),

CodePudding user response:

The values of $seeing and $tranparency are strings. Convert them to numbers before putting them into the array.

for ($i = 0; $i < 48; $i  = 1) {
    $hourly[$i] =
        array(
            "seeing" => floatval($seeing[$i])),
            "transparency" => floatval($transparency[$i]),
            "time" => $timeforapi[$i]
        );
}
  • Related