I'm about using CodeIgniter for my first project. I have tried to get data from database.
$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 )
)
And I got this. So, I need to call each element by:
foreach ($test as $ts){
echo $ts['id'];
}
My question is, can I make the array shorten. Just like:
Array (
[0] => 1
[1] => 4
[2] => 7
)
I will be appreciated for anyone's advise.
Use array_column
$test = array_column($test,'id');
foreach ($test as $ts){
echo $ts;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.