我要在我的第一个项目中使用CodeIgniter。我试着从数据库中获取数据。
$test = $this->komponen_model->get_participants_id()->result_array();
print_r($test)
Array (
[0] => Array ( [id] => 1 )
[1] => Array ( [id] => 4 )
[2] => Array ( [id] => 7 )
) 我来搞定这个。因此,我需要通过以下方式调用每个元素:
foreach ($test as $ts){
echo $ts['id'];
}我的问题是,我能不能缩短数组。就像:
Array (
[0] => 1
[1] => 4
[2] => 7
) 任何人的建议,我将不胜感激。
发布于 2017-04-24 06:32:24
使用array_column
$test = array_column($test,'id');
foreach ($test as $ts){
echo $ts;
}https://stackoverflow.com/questions/43581177
复制相似问题