<?php
i have decalered the array before the for loop
$sample=array();
I am Fetching database data which is in form of eg 5,6,2 i had imploded the before and stored them
$myseats= $db->displaySeats($showtime_id);
foreach ($myseats as $key) {
$bookedseats= $key['seats_booked'];
Exploding the values to $test variable
$test=explode(",", $bookedseats);
array_push($sample,$test);
}
print_r($sample) ;
?>
the problem is I am getting this output
Array ( [0] => Array ( [0] => 22
[1] => 26
[2] => 27
[3] => 37
[4] => 38
[5] => 41
)
[1] => Array ( [0] => 30
[1] => 31
[2] => 32
)
)
that is two arrays inside an array..the database has this two entries which am using a test
CodePudding user response:
You can use array_merge
PHP docs
CodePudding user response:
Instead of pushing arrays into an array, use array_merge(
) instead to place all these items into a single array as part of your loop
$sample = [];
foreach ( $rows as $bookedseats ){
$test=explode(",", $bookedseats);
$sample = array_merge($sample, $test);
}