foreach - Retrieve values from multi dimensional array using Sphinx PHP API -


i'm building search engine sphinx, i'm stuck @ end displaying results php knowledge limited. request search server gives me multi dimensional array:

array (     [0] => array         (             [id] => 327919409             [weight] => 3             [attrs] => array                 (                     [group_id] => 327919409                     [date] => 2013                 )          )      [1] => array         (             [id] => 84811232             [weight] => 2             [attrs] => array                 (                     [group_id] => 84811232                     [date] => 2013                 )          )      [2] => array         (             [id] => 150252575             [weight] => 2             [attrs] => array                 (                     [group_id] => 150252575                     [date] => 2013                 )          )      [3] => array         (             [id] => 174947829             [weight] => 2             [attrs] => array                 (                     [group_id] => 174947829                     [date] => 2013                 )          )      [4] => array         (             [id] => 297809970             [weight] => 2             [attrs] => array                 (                     [group_id] => 297809970                     [date] => 2013                 )          )      [5] => array         (             [id] => 391669252             [weight] => 2             [attrs] => array                 (                     [group_id] => 391669252                     [date] => 2013                 )          )  ) 

i need retrieve , list id values, i'm trying use code null values foreach:

$query = $_get['q']; $index = "test1"; require_once('sphinxapi.php'); //sphinx $s = new sphinxclient; $s->setserver("localhost", 9312); $s->setmatchmode(sph_match_all); $s->setarrayresult(true);  //search query $result = $s->query($query, $index);  if ($result['total'] > 0) {          foreach ($result['matches'] $key => $id) {             $ido = $id[$key]->id;                 //get column                 $searchcolumn = mysql_fetch_array( mysql_query("select * rasti_failai id=$ido") );                  //dump                 var_dump($searchcolumn);                     }   } else {         echo 'no results found';         } 

any correcting foreach loop appreciated.

you need change below line in foreach loop

$ido = $id[$key]->id; 

replace below

$ido = $id["id"]; 

you looping through array , can access mulch-dimentional array square brackets, using syntax object property.


Comments