display different suffix for each array element in codeigniter php -


$all_categories=get_cats($cat); $headingprinted = false; $childcount = 0; for($i=0;$i<sizeof($all_categories);$i++) {       $arr=get_gender($cat);   if($arr[$i]=='0')   {     if (!$headingprinted) {      echo "&nbsp&nbsp"."sons:";       $headingprinted = true;     }    echo "&nbsp&nbsp".$all_categories[$i].",";  $childcount++;  }     }       if ($childcount >= 3) { echo $childcount,  $childcount == 1 ;   }  else { // may want if none found } $headingprinted = false; $childcount = 0;  for($i=0;$i<sizeof($all_categories);$i++) {       $arr=get_gender($cat);    if($arr[$i]=='1'){ if (!$headingprinted) {      echo "&nbsp&nbsp"."daughters:";       $headingprinted = true;     }   echo "&nbsp&nbsp".$all_categories[$i].","; $childcount++;   }    }   if ($childcount >= 3) {  echo $childcount,  $childcount == 1 ;    }   else { // may want if none found  } 

i displaying word "sons" names count , word "daughters" names count. want display this
sons: a,b,c,d:4;
daughters:p,q,r,s:4;
$all_categories array in m getting child of given id , get_gender , get_cats functions.

now m displaying a,b,c,d, :4;. want remove comma after last element of array..
want display count if count of sons greater 2 , same daughters.
if boys count 1 word "sons:"a; , same daughters.
if boys count 2 word "sons:" a,b; , same daughters.
if boys count greater 2 word "sons:" a,b,c:3; , same daughters.
want display result same above said. can tried this???

to remove last comma on last of displaying sons , daughters, check if next record exist append comma, else escape comma.

$all_categories=get_cats($cat); $headingprinted = false; $childcount = 0; for($i=0;$i<sizeof($all_categories);$i++) {       $arr=get_gender($cat);   if($arr[$i]=='0')   {     if (!$headingprinted) {      echo "&nbsp&nbsp"."sons:";       $headingprinted = true;     }    echo "&nbsp&nbsp".$all_categories[$i];   if(isset($all_categories[$i+1])){       echo ",";     }  $childcount++;  }     }       if ($childcount >= 3) { echo $childcount,  $childcount == 1 ;   }  else { // may want if none found } $headingprinted = false; $childcount = 0;  for($i=0;$i<sizeof($all_categories);$i++) {       $arr=get_gender($cat);    if($arr[$i]=='1'){ if (!$headingprinted) {      echo "&nbsp&nbsp"."daughters:";       $headingprinted = true;     }   echo "&nbsp&nbsp".$all_categories[$i]; if(isset($all_categories[$i+1])){   echo ",";    }     $childcount++;       }    }   if ($childcount >= 3) {  echo $childcount,  $childcount == 1 ;    }   else { // may want if none found  } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -