Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove quotes from a PHP variable (PHP API)

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"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]),

>Solution :

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]
        );
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading