Hi guys,..i've two arrray data1 and data2 then i do intersect to get same value between data1 and data2, and >use count to get total same value,..how to ARSORT count result from intersect array multidimensional?

<?php
$data1 = array(
    array(
        '7' => 'chelsea everton',
        '8' => 'everton villa',
        '9' => 'villa liverpool',
        '10' => 'liverpool manutd'
    ),
    array(
        '23' => 'milan inter ',
        '24' => 'inter juventus',
        '25' => 'juventus napoli',
    ),
    array(
        '53' => 'chelsea everton',
        '54' => 'barcelona altetico',
        '55' => 'altetico getafe',
        '56' => 'everton villa',
    )
);
$data2 = array(
    array(
        '3' => 'milan inter',
        '4' => 'inter juventus',
        '5' => 'juventus napoli',
    ),
    array(
        '117' => 'swansea everton',
        '118' => 'everton villa',
        '119' => 'villa liverpool',
        '120' => 'liverpool manutd'
    ),
    array(
        '123' => 'milan inter ',
        '124' => 'inter juventus',
        '125' => 'juventus napoli',
    ),
    array(
        '137' => 'chelsea everton',
        '138' => 'everton villa',
        '139' => 'villa liverpool',
        '140' => 'liverpool manutd'
    )
);

$new_array = array();
foreach ($data1 as $in1 => $h1)
{
    foreach ($data2 as $in2 => $h2)
    {
        $match = array_unique(array_intersect($h1, $h2));
        echo count($match) . "";
    }
    echo "||";
}
?>

This code result like this: 
0304||2030||0102||

How to arsort count result to be like this? 
4300||3200||2100||
Member Avatar for LastMitch

ARSORT count result from intersect array multidimensional

Can you post your array code?

foreach ($data1 as $in1 => $h1)
{
    // temporary array for inner loop, needed for sorting
    $count_arr_temp = array();

    foreach ($data2 as $in2 => $h2)
    {
        $match = array_unique(array_intersect($h1, $h2));
        // put count data in a temporary array
        $count_arr_temp[] = count($match);
    }

    // sort temporary array
    rsort($count_arr_temp);

    // didplay sorted elements
    foreach($count_arr_temp as $count) {

        echo $count;
    }

    // add the delimiter
    echo '||';
}
commented: Nice Code! +7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.