我已經比較了一個矩陣的數據,我已經統計了一個數組的數據,但是我從來沒有數過,數組之間重複的按鍵序列是什麼,我想在所有序列之間進行比較,並查找out這個部分的最大尺寸重複..我有數百個數字,我應該在它們之間進行比較,找出它們之間最大的重複延伸,一個序列中存在的最大重複尺寸,另一個存在於另一個大陣列的序列!如何比較大數組中的關鍵序列,找出最大數量的重複序列?
查找重複的單個元素可以簡單地用in_array()完成。 array_keys()同樣可以輕鬆地從不同數組中重複鍵。由於我們關注的是序列,而不是單一的值,所以它們對我們都沒有幫助。
<?php
header('Content-Type: text/html; charset=utf-8');
echo 'test - This is just for us to figure out, what is the size of the greatest duplication of stretches between the previous sequences'.'<br>';
$previous_results_manually_inserted = array(
array('12','21','34','1','51','87','42','49','37','119','101','7','111','17','11','19','2','15','6'),
array('3','5','1','18','61','75','92','84','36','81','2','07','90','2','71','17','08','51','37'),
array('81',75','92','84','36','81','2','07','90','2','17','65','44','73','27','30','41','74','88'),
);
foreach ($previous_results_manually_inserted as $previous) {
$match = preg_match("/.*$test.*/", $previous);
}
echo 'The largest repeated slice between these sequences is:';
echo implode(', ', $match), "<br>\n"
輸出:75' , '92', '84', '36', '81', '2', '07', '90', '2'
注:最終客觀:最高的重複性是9個數字。 (在這個例子中)
謝謝大家。
你想找到'$ previous_results_manually_inserted =陣列( 陣列複製('12' , '21', '34', '1', '51','87 」,'42' , '49', '37', '119', '101', '7', '111', '17', '11', '19', '2', '15', '''','3','5','1','18','61','75','92','84','36','81','2' '','07','90','2','71','17','08','51','37'), 陣列('81',75','92',' 84' , '36', '81', '2', '07', '90', '2', '17', '65', '44', '73', '27', '30' ,'41','74','88'), );' –
'$ test'中包含了什麼? 'preg_match'返回一個布爾值,對它應用'implode'是無稽之談。 '$ match'在每次循環迭代中重新初始化。 – Toto