更新
<?php
$items=
array(
array('no'=>"1", 'subtitle'=>"Perbekalan", 'title'=>"lombok ijo"),
array('no'=>"3",'subtitle'=>"Inventaris", 'title'=>"Wajan"),
array('no'=>"2",'subtitle'=>"Perbekalan", 'title'=>"bawang abang")
);
foreach($items as $item)
$output[$item['subtitle']][] = $item;
extract($output);
var_export($Perbekalan);
echo "\n";
var_export($Inventaris);
輸出:
array (
0 =>
array (
'no' => '1',
'subtitle' => 'Perbekalan',
'title' => 'lombok ijo',
),
1 =>
array (
'no' => '2',
'subtitle' => 'Perbekalan',
'title' => 'bawang abang',
),
)
array (
0 =>
array (
'no' => '3',
'subtitle' => 'Inventaris',
'title' => 'Wajan',
),
)
相反cretainf兩個單獨數組變量的這更好: - '$陣列=陣列(0 =>數組( 陣列(沒有= 「1」,字幕= 「Perbekalan」, title =「lombok ijo」), array(no =「2」,subtitle =「Perbekalan」,title =「bawang abang」)),1 => array( array(no =「3」,subtitle =「Inventaris 「,title =」Wajan「)) );'。你不這麼認爲嗎?還有你如何創建'$ array'?該代碼部分丟失。因此,添加 –
array_slice將是有用的\ – TarangP
試試這個http://php.net/manual/en/function.array-chunk.php –