Jump to content

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;
    }
}
Edited by Barand
Link to comment
https://forums.phpfreaks.com/topic/276908-compare-arrays/#findComment-1424589
Share on other sites

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

Edited by thecase
Link to comment
https://forums.phpfreaks.com/topic/276908-compare-arrays/#findComment-1424591
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.