Home > Back-end >  How can I convert one value from int to string within an array
How can I convert one value from int to string within an array

Time:07-08

enter image description hereI want to make my chart data.addColumn ('string', 'hour'); must be a string. In my request it is an int.

$temp_array = array();
while($row = mysqli_fetch_assoc($result))
{
    $temp_array = array(strval($row["hour"]), $row["min"], $row["max"], $row["Avg"]);
}

result now: "["6","30.0","30.0","30.0"]" want only the first one("6") between quotes.

php code

javascript

CodePudding user response:

Use the strval() to convert integer value to string. For example:

$temp_array[] = array( strval($row["hour"]), strval($row["min"]));

CodePudding user response:

$temp_array = array();
while($row =mysqli_fetch_assoc($result))
{
    $temp_array[] = array( (string)$row["hour"], $row["min"], $row["max"], $row["Avg"]);
}

CodePudding user response:

strval($row["hour"]) should do the trick.

  • Related