【发布时间】:2018-06-27 09:25:25
【问题描述】:
下面的函数,即 getBooksInsertedCount 代码给出这样的输出
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
[2]=>
string(1) "1"
}
getBooksInsertedCount
function getBooksInsertedCount()
{
$this->load->database();
$query = "SELECT count(book_id) as count,date(created_date) as cdate FROM `bookdetails` WHERE (created_date BETWEEN '2018-06-25' AND '2018-06-28') GROUP by created_date order by created_date asc";
$result = $this->db->query($query);
$ret = array();
foreach ($result->result_array() as $row ) {
$ret[] = $row['count'];
}
return $ret;
}
预期输出(此处注意:[0]=> 字符串(1)已删除)
array(1, 2, 1);
【问题讨论】:
-
你发布的当前输出和预期输出是一样的。
-
只要转换成int就行了
$ret[] = $row['count']; -
除了
int和string类型有什么区别? -
每个数组都有索引:如果你 var_dump
$a = [1,2,3]它会给你array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
标签: php codeigniter