可以使用PHP的array_merge()函數將二維數組轉化為一維數組。具體操作如下:
$twoDimensionalArray = array(
array('apple', 'banana'),
array('orange', 'grape'),
array('melon', 'watermelon')
);
$oneDimensionalArray = array();
foreach ($twoDimensionalArray as $subArray) {
$oneDimensionalArray = array_merge($oneDimensionalArray, $subArray);
}
print_r($oneDimensionalArray);
輸出結果為:
Array
(
[0] => apple
[1] => banana
[2] => orange
[3] => grape
[4] => melon
[5] => watermelon
)