{"id":305,"date":"2017-11-21T09:55:37","date_gmt":"2017-11-21T09:55:37","guid":{"rendered":"http:\/\/info.juliusgoh.life\/?p=305"},"modified":"2018-01-09T04:56:45","modified_gmt":"2018-01-09T04:56:45","slug":"array-difference-between-large-arrays-php","status":"publish","type":"post","link":"https:\/\/info.juliusgoh.life\/?p=305","title":{"rendered":"Array Difference Between Large Arrays (PHP)"},"content":{"rendered":"<p>Hi, today i&#8217;ve encounter a two large array to be compare. Array 1 is around 50k data and Array 2 is around 500k data. So what i wanna eliminate is , If Array2&#8217;s data exist in Array1 , i want it out from Array 2. So here&#8217;s what i will normally do (SLOW VERSION \ud83d\ude41 boooo &#8230;.)<\/p>\n<pre>\r\n$Array1 = .........;\r\n$Array2 = .........;\r\n\r\n$Array2 = array_diff($Array2,$Array1);\r\n$Array2 = array_values($Array2);\r\n<\/pre>\n<p>Now , i would like to perform a quick diff method (FASTER VERSION)<\/p>\n<pre>\r\n$Array1 = .........;\r\n$Array2 = .........;\r\n\r\n#Perform Fliiping\r\n$Array1 = array_flip($Array1);\r\n$Array2 = array_flip($Array2);\r\n\r\n#Compare Using Keys\r\n$Array2 = array_diff_key($Array2,$Array1);\r\n\r\n#Finally , rearrange your array into normal array pattern\r\n$Array1 = $array_keys($Array1);\r\n$Array = $array_keys($Array2);\r\n<\/pre>\n<p>There you go , This is the result of If Array2&#8217;s values exist in Array1 It will be Filtering\/removed\/Unset out from Array2. Enjoy \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, today i&#8217;ve encounter a two large array to be compare. Array 1 is around 50k data and Array 2 is around 500k data. So what i wanna eliminate is , If Array2&#8217;s data exist in Array1 , i want it out from Array 2. So here&#8217;s what i will normally do (SLOW VERSION \ud83d\ude41 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":223,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts\/305"}],"collection":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=305"}],"version-history":[{"count":1,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts\/305\/revisions"}],"predecessor-version":[{"id":306,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts\/305\/revisions\/306"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/media\/223"}],"wp:attachment":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}