0

I have two array I want to match ['Name'] value of second array [Seltemgr] value, if ['Name']=>value == [Seltemgr]=>value then <input type="checkbox" checked="checked"> else unchecked, Is this possible to match two multidimensional array having different no of element with different keys.

Array
(
[0] => Array
    (
        [tnid] => 45
        [Name] => Financial Tips      
        [Email] => Array
        [Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/5
    )

[1] => Array
    (
        [tnid] => 42
        [Name] => Products            
        [Email] => Array
        [Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/2
    )

[2] => Array
    (
        [tnid] => 44
        [Name] => Health Tips         
        [Email] => Array
        [Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/4
    )

[3] => Array
    (
        [tnid] => 43
        [Name] => Personal Events     
        [Email] => Array
        [Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/3
    )

[4] => Array
    (
        [tnid] => 41
        [Name] => Calendar            
        [Email] => Array
        [Href] => http://amt-ars-d.sevenverbs.com/api/v1/emailtemplategroups/1
    )

  )

  Array
  (
[0] => Array
    (
        [emarketid] => 77
        [agentid] => 81
        [customerid] => 16901
        [Seltemgr] => Calendar                                          
        [seltemname] => 
    )

[1] => Array
    (
        [emarketid] => 78
        [agentid] => 81
        [customerid] => 16901
        [Seltemgr] => Financial Tips                                    
        [seltemname] => 
    )

[2] => Array
    (
        [emarketid] => 79
        [agentid] => 81
        [customerid] => 16901
        [Seltemgr] => Merry Christmas                                   
        [seltemname] => 
    )

[3] => Array
    (
        [emarketid] => 80
        [agentid] => 81
        [customerid] => 16901
        [Seltemgr] => Drip financial tip 3                              
        [seltemname] => 
    )

  )
ByteHamster
  • 4,884
  • 9
  • 38
  • 53

1 Answers1

0
$match = [];

foreach ($array1 as $k1=>$a1){
      foreach($array2 as $k2=>$a2){
                 if($a2['Seltemgr'] == $a1['Name']){
                         $match[] = array($k1,$k2);
                 }
       }
}

So $match contains the index of each array where the Name and Seltemgr match. Not saying this is the optimal way to do this but The intersect functions often require keys to match up.

nickL
  • 1,536
  • 2
  • 10
  • 15