2
我有以下陣列或多個陣列:PHP:將數組拆分爲基於自定義函數的塊?
$bigArray = array(
array(
id = 3,
text = "Hello World"
),
array(
id = 3,
text = "Taco"
),
array(
id = 10,
text = "Foo"
),
array(
id = 10,
text = "Bar"
),
array(
id = 10,
text = "dogfood"
)
);
我想能夠陣列成基於關ID號的多個陣列的陣列分裂像這樣:
$arrayOne = array(
array(
id = 3,
text = "Hello World"
),
array(
id = 3,
text = "Taco"
)
);
$arrayTwo = array(
array(
id = 10,
text = "Foo"
),
array(
id = 10,
text = "Bar"
),
array(
id = 10,
text = "dogfood"
)
);
我可以找到的cloest PHP函數是array_chunk()
,但它僅適用於數字索引。是否有任何類似的功能可以根據自定義書寫功能進行組塊分割決策?
我知道我可以編寫一個自定義函數來遍歷bigArray並手動執行此操作,但我首先要問的是,如果先有任何本機方法。