<?php
我在 for 回圈之前對陣列進行了 decalered
$sample=array();
我正在獲取例如 5,6,2 形式的資料庫資料,我之前已經內爆并存盤了它們
$myseats= $db->displaySeats($showtime_id);
foreach ($myseats as $key) {
$bookedseats= $key['seats_booked'];
將值分解為 $test 變數
$test=explode(",", $bookedseats);
array_push($sample,$test);
}
print_r($sample) ;
?>
問題是我得到這個輸出
Array ( [0] => Array ( [0] => 22
[1] => 26
[2] => 27
[3] => 37
[4] => 38
[5] => 41
)
[1] => Array ( [0] => 30
[1] => 31
[2] => 32
)
)
這是一個陣列中的兩個陣列..資料庫有這兩個正在使用測驗的條目
uj5u.com熱心網友回復:
您可以使用array_merge
PHP 檔案
uj5u.com熱心網友回復:
不是將陣列推入陣列,而是使用array_merge() 將所有這些專案放入一個陣列中作為回圈的一部分
$sample = [];
foreach ( $rows as $bookedseats ){
$test=explode(",", $bookedseats);
$sample = array_merge($sample, $test);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/376768.html
