How to find number of inbound links in php if i have array of linking between pages? -
i have 2d array represent outgoing links of each page returned search engine, have find number of inbound links of each page.
eg 1 present in sub array in key2,3,4,5,6 number of inbound 5.
i need in php.
$links = array( 1 => array(2,3,4,5,6), 2 => array(1,3,4,5,6), 3 => array(1,2,4,5,6), 4 => array(1,2,3,5,6), 5 => array(1,2,3,4,6), 6 => array(1,2,3,4,5), 7=> array (11), 8=>array(7,9), 9=> array(7), 10=> array(8), 11=> array(8,10), );
probably cleaner way, 1 way create new array, loop on existing array, , add new array using value key.
$results=array(); foreach($links $link){ foreach($link $value){ $results[$value] = isset($results[$value]) ? $results[$value]+1 : 1; } }
with example data, results -
array ( [1] => 5 [2] => 5 [3] => 5 [4] => 5 [5] => 5 [6] => 5 [7] => 2 [8] => 2 [9] => 1 [10] => 1 [11] => 1 )
Comments
Post a Comment