Jump to content

Why are variables lost from this multy-dimensional array?


Go to solution Solved by requinix,

Recommended Posts

I'f I do a var_dump after taking in the array from the foreach statement then all of the variables are present. However, by the time the variables go through the switch statement and we run the first case it only prints out the URL for most of the results and URL_title for others.

 

foreach ($js -> results as $item)
        {
            $Faroo[$o] = array 
            ('url'=>$item->url, 
            'url_title'=>$item->title,    
            'snippet' =>$item->kwic,
            'rank' => 100-$o,
            'engine' => 'Faroo');        
//var_dump($Faroo[$o]);
            $o++;
        }
$s=$s+10;
$e=$e+10;
}
  }
?>       
<?php
$agg =  $_POST['agg'];
$full_count=0;
switch ($agg)
{
    case 'Aggregated':
     while ($full_count<=$bing_count)              //while m <= bing results               m = 0;
    {
        $r_set[$full_count] = $bing_results[$full_count];      //load bing[m] in to r_set[m] 
        $full_count++;                               //m = increments for every bing result 
    }       
    
$b_count=0; 
$r_count=0;                             //reset b_count so we can start again and create r_count so we can loop through the existing unilist
        while ($b_count<$blekko_count)                       // 0 < blekko
        {                                                               // We reset postion in
             while ( $Blekko[$b_count]['url']!=$r_set[$r_count]['url'])
                 {                                                      //check that the url is not already in the list
                    $r_count++;                                               //increment z to loop through the full r_set  
                    if ($r_count>$full_count)               //When r_count counts through the full_count break (after finding all the matches)//should that not be b_count? 
                    {
                    break;   
                    }                                   
                 }


        if ( $Blekko[$b_count]['url'] == $r_set[$r_count]['url'])
            {                                           //if it is in the list then add the score                                                                      
                $r_set[$r_count]['rank']+=$Blekko[$b_count]['rank'];
                $b_count++;                                       //move to next element
                                
            }
            else
            {                                    //if not in the list then add it
                $full_count++;                          //y is used to increment on from this point
                $r_set[$full_count]=$Blekko[$b_count];
                $b_count++;   //if r_count is not larger then full count and url's do not match then we increment b_count
            }    
                
         }    
                                       
$b_count=0; 
$r_count=0; //reset both counters again
       while ($b_count<$o)
       {                                                // We reset postion in
            while ( $Faroo[$b_count]['url']!=$r_set[$r_count]['url'])
            { //check that the url is not already in the list             
                    $r_count++;
       
             if ($r_count>$full_count)
            {
                break;    
            }
            }


        if ( $Faroo[$b_count]['url'] == $r_set[$r_count]['url'])
        { //if it is in the list then add the score
                                         
                                         
             $r_set['rank'][$r_count]+=$Faroo[$b_count]['rank'];
             $b_count++; //move to next element                              
        }
        else
        { //if not in the list then add it
            $full_count++; //y is used to increment on from this point
            $r_set[$full_count]= $Faroo[$b_count];
            $b_count++;
        }        
                
        }


            echo $full_count;
  
   
   array_multisort($r_set, SORT_ASC, 'rank');              //not sure if this works or not yet 
   $echo_l = 0;
   while ($echo_l<=$full_count)
    {
        echo 'URL: '.$r_set[$echo_l]['url'].'<br>';
        echo 'URL TITLE: '.$r_set[$echo_l]['url_title'].'<br>';
        echo 'SNIPPET: '.$r_set[echo_l]['snippet'].'<br>';
        echo 'RANK: '.$r_set[echo_l]['rank'].'<br>';
        echo 'ENGINE: '.$r_set[echo_l]['engine'].'<br>';
        var_dump($Blekko[$echo_l]);
        $echo_l++;
    } 

 

  • Solution

Your code is rather difficult to read, indentation being one of the main problems, but I do see

echo 'URL: '.$r_set[$echo_l]['url'].'<br>';
echo 'URL TITLE: '.$r_set[$echo_l]['url_title'].'<br>';
echo 'SNIPPET: '.$r_set[echo_l]['snippet'].'<br>';
echo 'RANK: '.$r_set[echo_l]['rank'].'<br>';
echo 'ENGINE: '.$r_set[echo_l]['engine'].'<br>';
you're missing some $s.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.