thecase Posted April 13, 2013 Share Posted April 13, 2013 Hi, I'm trying to compare arrays but they have different levels of keys Array 1 array (size=1)'fdate' => string '2013-04-14' (length=10)array (size=1)'fdate' => string '2013-04-21' (length=10) Array 2array (size=7)0 => string '2013-04-14' (length=10)1 => string '2013-04-21' (length=10)2 => string '2013-04-28' (length=10)3 => string '2013-05-05' (length=10)4 => string '2013-05-12' (length=10)5 => string '2013-05-19' (length=10)6 => string '2013-05-26' (length=10) I've tried to compare using array_diff but this only finds a difference on the first entry for array 1 I assumed due to the different way it set up. Any ideas how I can get this to work Thanks Link to comment https://forums.phpfreaks.com/topic/276908-compare-arrays/ Share on other sites More sharing options...
mac_gyver Posted April 13, 2013 Share Posted April 13, 2013 what result are you trying to achieve? comparing them using what condition or rule? Link to comment https://forums.phpfreaks.com/topic/276908-compare-arrays/#findComment-1424583 Share on other sites More sharing options...
Barand Posted April 13, 2013 Share Posted April 13, 2013 you could convert array1 to same format as array2 $array1 = array ( array ('fdate' => '2013-04-14'), array ('fdate' => '2013-04-21') ); $array3 = array(); foreach ($array1 as $k => $dates) { foreach ($dates as $d) { $array3[$k] = $d; } } Link to comment https://forums.phpfreaks.com/topic/276908-compare-arrays/#findComment-1424589 Share on other sites More sharing options...
thecase Posted April 13, 2013 Author Share Posted April 13, 2013 I'm trying to comapre the two arrays for duplicates and set up an array with the dates that arent duplicated. I don't have control over the 1st array as it comes from the database but I can change the 2nd array. I'll try what you suggested Barand thanks Link to comment https://forums.phpfreaks.com/topic/276908-compare-arrays/#findComment-1424591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.