0

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||
3
Contributors
2
Replies
6
Views
4 Years
Discussion Span
Last Post by broj1
4

ARSORT count result from intersect array multidimensional

Can you post your array code?

2
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 '||';
}

Edited by broj1

Votes + Comments
Nice Code!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.