<?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
My Answer:
Sure, you can merge two arrays in PHP using the `array_merge()` function. Here's an example of how you can merge two arrays into one:
php
$array1 = array("apple", "banana", "orange");
$array2 = array("grape", "kiwi", "pineapple");
$mergedArray = array_merge($array1, $array2);
print_r($mergedArray);
Output:
Array
(
[0] => apple
[1] => banana
[2] => orange
[3] => grape
[4] => kiwi
[5] => pineapple
)
This will merge the elements of both arrays into a single array.
Rate this post
4 of 5 based on 5069 votesComments