[英]How to convert an SQL result string to an array in Codeigniter?
To convert your $array 1 [picture_names] into an array itself, you can use the " explode() " function. 要将$ array 1 [picture_names]转换为数组本身,可以使用“ explode() ”函数。
array explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] )
Ie in your specific example: 即在您的特定示例中:
$results = $this->db->get()->result_array();
$exp_results = explode(',', $results);
Which should give an array as such: 应该给出这样的数组:
$exp_results = Array (
0 => 21
1 => 22
2 => 25
3 => 27
4 => .... etc
)
Add these lines after query 查询后添加这些行
$result = $this->db->get()->result_array();
foreach($result as $key=>$row) {
$result[$key]['picture_names'] = explode(',',$row['picture_names']);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.