note 99934 deleted from control-structures.for by danbrown

From: Date: Thu, 16 Sep 2010 15:55:04 +0000
Subject: note 99934 deleted from control-structures.for by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172656@lists.php.net to get a copy of this message
Note Submitter: myfavoritecreator ---at---yahoo.com ---- I use for() loop specially to indicate indexes in an array. I could use foreach() with this, but I still prefer for() because we can control our flow, or things we want. I just wrote this code to gain combination with the keywords. <?php $keywords_array =array("Learn Programming","PHP Programming","quick brown","code","apple","brown"); // process keywords $final_keywords=""; $final_keywords_smaller=""; $keywordscount=count($keywords_array); for($i=0;$i < ($keywordscount); $i++ ){ $final_keywords.=$keywords_array[$i]; if( $i<$keywordscount-1 ){ $final_keywords.=","; } // explode each key $pieces = explode(" ", (string)$keywords_array[$i]); // check if arry counts is more than 1 if( count($pieces) > 1 ){ $final_keywords_smaller.= implode(",", $pieces).","; // implode with comma's } } echo "keywords ORIGINALS: $final_keywords<br><br>"; // keywords ORIGINALS: Learn Programming,PHP Programming,quick brown,code,apple,brown echo "keywords SMALLER: $final_keywords_smaller<br><br>"; // keywords SMALLER: Learn,Programming,PHP,Programming,quick,brown, $final_keywords = strtolower ($final_keywords_smaller.$final_keywords); // append $final_keywords = explode(",", $final_keywords); // explode $final_keywords = array_unique($final_keywords); // no repeating $final_keywords = implode(",", $final_keywords); // implode with comma's echo "Final keywords: $final_keywords"; // keywords: learn,programming,php,quick,brown,learn programming,php programming,quick brown,code,apple ?>

« previous php.notes (#172656) next »