php - Printing the repeated values -
how rid of repeated values .....
foreach($get_all $key => $value) { $v = 1; foreach($value $loc) { foreach($loc $l) { $new[] = $l['id']; } } $new = array_unique($new); $total = count($new); unset($new); if($v) { $v =0 ; $body .= "<tr><td>{$value[0][0]['location']}</td><td>{$total}</td></tr>"; continue; } }
the above code gives ouptput:
koramangala 63 koramangala 63 indiranagar 36 koramangala 63 indiranagar 36 mg road 16 koramangala 63 indiranagar 36 mg road 16 btm 35
but need :
koramangala 63 indiranagar 36 mg road 16 btm 35
what have chage required output?/??
you can this
$printed = array(); // initialize array store printed values foreach($get_all $key => $value) { $v = 1; foreach($value $loc) { foreach($loc $l) { $new[] = $l['id']; } } $new = array_unique($new); $total = count($new); unset($new); if($v) { $v =0 ; if (!in_array($value[0][0]['location'], $printed)){ //check if not printed $body .= "<tr><td>{$value[0][0]['location']}</td><td>{$total}</td></tr>"; $printed[]=$value[0][0]['location']; //store printed location array } continue; //this not required last line } }
note: don't know why using $v
(may have posted relevant parts only). structure of data not clear may not best (optimized) option.
Comments
Post a Comment