Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 查询应返回整数和字符串CI_Php_Mysql_Json_Codeigniter - Fatal编程技术网

Php 查询应返回整数和字符串CI

Php 查询应返回整数和字符串CI,php,mysql,json,codeigniter,Php,Mysql,Json,Codeigniter,我得到了以下查询,返回日期(字符串值)和数字(整数值) 但是当我在控制器中转储结果时,我得到一个只有字符串的数组。这些值应该是整数,以便在图形中使用它们 只是阵列的第一部分: array(25) { [0]=> object(stdClass)#169 (2) { ["x"]=> string(10) "2013-10-16" ["y"]=> string(7) "3283581" } [1]=> object(stdC

我得到了以下查询,返回日期(字符串值)和数字(整数值)

但是当我在控制器中转储结果时,我得到一个只有字符串的数组。这些值应该是整数,以便在图形中使用它们

只是阵列的第一部分:

array(25) {
  [0]=>
  object(stdClass)#169 (2) {
    ["x"]=>
    string(10) "2013-10-16"
    ["y"]=>
    string(7) "3283581"
  }
  [1]=>
  object(stdClass)#160 (2) {
    ["x"]=>
    string(10) "2013-10-17"
    ["y"]=>
    string(7) "1512116"
  }
我正在处理此数组以创建Json对象:

    $_rows = array();

    foreach ($rows as $i => $row) {
        foreach ($row as $column => $value) {
            $_rows[$i][$column] = $value;
        }
    }       

    $rows = $_rows;         

    echo json_encode(array("className" => ".main.l1","data" => $rows));
但是JSON对象包含字符串形式的值,而不是所需的整数。我应该换什么

JSON输出示例:

    {"className":".main.l1","data":[{"x":"2013-10-16","y":"3283581"},{"x":"2013-10-17","y":"1512116"},{"x":"2013-10-18","y":"3967"},{"x":"2013-10-19","y":"1094"},{"x":"2013-10-20","y":"853"},{"x":"2013-10-21","y":"1205"},{"x":"2013-10-22","y":"2618700"},{"x":"2013-10-23","y":"3928291"},{"x":"2013-10-24","y":"3670318"},{"x":"2013-10-25","y":"3347369"},{"x":"2013-10-26","y":"2525573"},{"x":"2013-10-27","y":"3224612"},{"x":"2013-10-28","y":"3992964"},{"x":"2013-10-29","y":"3949904"},{"x":"2013-10-30","y":"3568618"},{"x":"2013-10-31","y":"3104696"},{"x":"2013-11-01","y":"3246932"},{"x":"2013-11-02","y":"2817758"},{"x":"2013-11-03","y":"3198856"},{"x":"2013-11-04","y":"3952957"},{"x":"2013-11-05","y":"3934173"},{"x":"2013-11-06","y":"3878718"},{"x":"2013-11-07","y":"3642822"},{"x":"2013-11-08","y":"3388646"},{"x":"2013-11-09","y":"376763"}]}

有人能帮我解决这个问题吗?

试试这样的办法

尝试检查值是否为整数。如果为整数,则将其解析为字符串

     foreach ($rows as $i => $row) {
        foreach ($row as $column => $value) {
            if(is_numeric($value)){
                $_rows[$i][$column] = intval($value);
            }else{
                $_rows[$i][$column] = $value;
            }
        }
    } 

非常感谢您的帮助,这就是解决方案!我的图表正在运行!
     foreach ($rows as $i => $row) {
        foreach ($row as $column => $value) {
            if(is_numeric($value)){
                $_rows[$i][$column] = intval($value);
            }else{
                $_rows[$i][$column] = $value;
            }
        }
    }