#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0

    Compare multidimensional array elements


    Ok this is going to take some careful explaining. Here is my code.

    PHP Code:
    <?php



    if(isset($_POST['input']) && $_POST['input'] != "")


    {    

            echo 
    "<br />Your Search Result Array Blekko:<br /><br />";
     
        
    $u_r_l =  cantsay
        
        
     urlencode
    ($u_r_l );

        
        
        
    $body file_get_contents($u_r_l);
    $js=json_decode($body,true);
    //print_r($js);

    //echo $js;
    /***********************************************************************************
    foreach ($js['RESULT'] as $data) {
        echo '
            <p>
                ', $data ['url_title']," ---> <u>Blekko SE </u>" ,'<br />
                ', '<a href ='.$data['url'].'>'.$data['url']."</a>" , '<br />';
                
                if (empty ($data['snippet']) != true)
                echo $data['snippet'];  
                
    else echo"<p>";

    ********************************************************************************************************/




    $blekko_score 0;
    foreach(
    $js['RESULT'] as $data)
    {


    $blekko_array[] = array (
       
    $data['url_title'],
       array(
    $data['url'],$blekko_score++));
     }

     
    ?>
    $blekko_score is the score I want to assign for the url, and $blekko_score is the element at $blekko_array[0-99][1][1]). I have two other engines and i need to merge the url scores of the 3 engines into one large array. I then need to add the scores of duplicate urls together and display the 100 top results, along with the title. I have 2 days to do this and don't think I have a snowballs chance in hell of getting this done, thought that adding an incrementing score to a url and comparing the results wouldn't be that difficult, but has so far had loads of complications - incrementing counters don't work within foreach loop, simply giving a score to the element in the array, comparing elements of different arrays etc. The code for the other Search-engines is on the same page and is similar so if i can get the structure of this I'm confident I can twist it to suit the others.

    If anyone has any pseudo code, general advice, alternative solutions etc I'd really appreciated it, this has set me back for two days already.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,112
    Rep Power
    9398
    Put the URLs and scores into an array like
    PHP Code:
    $blekko_array[$url] = $score
    a) If the URL already exists in the array (check with isset()) then add to the score
    b) Otherwise add it as a new item

    Then arsort.

IMN logo majestic logo threadwatch logo seochat tools logo