1

MySQL array

image

CSV file array

image

I want to match this two different associative arrays "Url" value. Also I want remaining array value of CSV file i.e. DA, PA, MozRank, Linksln, and so on...

I hope some genius can help me

Thank you

3
  • Easy way is to compare array_column($array1, 'url') against array_column($array2, 'url') Commented Mar 20, 2017 at 11:36
  • What you need output Commented Mar 20, 2017 at 11:39
  • I want just matching URL value. Commented Mar 20, 2017 at 11:49

2 Answers 2

2

Check this custom PHP script returns you matched url from two array

 <?php
    /**
     * Function for match url and return data 
     */
    function matchArray($array1, $array2)
    {
        $index = 0;
        $return = array();
        $count1 = count($array1);
        $count2 = count($array2);
        for($i=0; $i < $count1; $i++)
        {
            for($j=0; $j < $count2; $j++)
            { 
                if($array1[$i]['url'] == $array2[$j]['url']) {
                    $return[$index]['url'] = $array2[$j]['url'];    // Add index which you want to get 
                    $return[$index]['DA'] = $array2[$j]['DA'];     // Add index which you want to get 
                    $return[$index]['PA'] = $array2[$j]['PA']; 
                    $return[$index]['MozRank'] = $array2[$j]['MozRank']; 
                }
                $index ++;
            }
        }
        echo "<pre>";
        print_r($return); // this will return matched url form two array 
    }
$array1 = array(array('url' => 'AllConsuming.net' ),array('url' => 'app.brand-mention.com'),array('url' => 'www.microsoft.com'));
    $array2 = array(array('url' => 'AllConsuming.net', 'DA' => 48, 'PA'=> 54.4, 'MozRank'=> 5.4),array('url' => 'www.microsoft.com', 'DA' => 31.7, 'PA'=> 54.4, 'MozRank'=> 5.4));

matchArray($array1, $array2); // calling function 
 ?>
Sign up to request clarification or add additional context in comments.

3 Comments

Hello, @Aman Kumar. Also, I have to need the remaining value of matched URL. i.e. DA, PA, MozRank and so on.. You can get the idea from above CSV file array. Thank you
Hello @Aman Kumar, Also, I have to update MySQL table. All fields of CSV file are available in MySQL table I need to just update match URL, remaining fields to MySQL existing table fields. Can you help me how can I do? Thank You...
Hello @Aman Kumar, Can you help me to find out unmatch URL from two array ?
2

If you want to know which entries are indentical, proceed this way :

$array1 = array_column($ar1, 'url'); // return array('AllConsuming.net', 'http://app.brand-mention.com', 'https://www.microsoft.com', 'otherstuff')
$array2 = array_column($ar2, 'url'); // return array('AllConsuming.net', 'TravelIntelligence.net', 'otherstuff')

// compare these 2 arrays
$comp = array_intersect($aray1, $array2);
var_dump($comp); // output array('AllConsuming.net', 'otherstuff');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.