我有一個幾乎有50K +子數組的數組。把所有的,爲了優先不是問題,所以我設法使它看起來像這樣:如何創建按交替優先級排序的數組?
$SendQueue = array(
array('3', '+553400000001', 'My text messege here'),
array('3', '+553400000002', 'My text messege here'),
array('3', '+553400000003', 'My text messege here'),
array('3', '+553400000004', 'My text messege here'),
array('3', '+553400000005', 'My text messege here'),
array('3', '+553400000006', 'My text messege here'),
array('3', '+553400000007', 'My text messege here'),
array('3', '+553400000008', 'My text messege here'),
array('3', '+553400000009', 'My text messege here'),
array('3', '+553400000010', 'My text messege here'),
array('3', '+553400000011', 'My text messege here'),
array('3', '+553400000012', 'My text messege here'),
array('2', '+553400000013', 'My text messege here'),
array('2', '+553400000014', 'My text messege here'),
array('2', '+553400000015', 'My text messege here'),
array('2', '+553400000016', 'My text messege here'),
array('2', '+553400000017', 'My text messege here'),
array('2', '+553400000018', 'My text messege here'),
array('1', '+553400000019', 'My text messege here'),
array('1', '+553400000020', 'My text messege here'),
);
//where '3', '2' and '1' are my priorities' types
我真正需要的是那些交替sub_arrays,這樣他們就可以是這樣的:
$SendQueue = array(
array('3', '+553400000001', 'My text messege here'),
array('3', '+553400000002', 'My text messege here'),
array('3', '+553400000003', 'My text messege here'),
array('3', '+553400000004', 'My text messege here'),
array('3', '+553400000005', 'My text messege here'),
array('3', '+553400000006', 'My text messege here'),
array('2', '+553400000013', 'My text messege here'),
array('2', '+553400000014', 'My text messege here'),
array('2', '+553400000015', 'My text messege here'),
array('1', '+553400000019', 'My text messege here'),
array('3', '+553400000007', 'My text messege here'),
array('3', '+553400000008', 'My text messege here'),
array('3', '+553400000009', 'My text messege here'),
array('3', '+553400000010', 'My text messege here'),
array('3', '+553400000011', 'My text messege here'),
array('3', '+553400000012', 'My text messege here'),
array('2', '+553400000016', 'My text messege here'),
array('2', '+553400000017', 'My text messege here'),
array('2', '+553400000018', 'My text messege here'),
array('1', '+553400000020', 'My text messege here'),
);
//Each 10 sub_arrays, 6 of them are priority '3', 3 of them are priority '2' and 1 of them is priority '1'
有誰知道該怎麼做?
RTLM:http://php.net/usort – 2013-04-29 17:32:55
之間PHP內置的陣列功能和循環沒有太多你不能做陣列。你只需*嘗試*。 – 2013-04-29 17:33:20
http://php.net/manual/en/class.splpriorityqueue.php – vascowhite 2013-04-29 17:34:05