Jump to content

Compare Arrays


thecase

Recommended Posts

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 2
array (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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.