note 99934 added to control-structures.for
| From: | myfavoritecreator---at---yahoo dot com at osu1 dot php dot net | Date: | Thu, 16 Sep 2010 02:43:17 +0000 |
| Subject: | note 99934 added to control-structures.for | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172618@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 69.147.83.197
Probable Submitter: 119.93.75.177
----
Manual Page -- http://www.php.net/manual/en/control-structures.for.php
Edit -- https://master.php.net/note/edit/99934
Del: integrated -- https://master.php.net/note/delete/99934/integrated
Del: useless -- https://master.php.net/note/delete/99934/useless
Del: bad code -- https://master.php.net/note/delete/99934/bad+code
Del: spam -- https://master.php.net/note/delete/99934/spam
Del: non-english -- https://master.php.net/note/delete/99934/non-english
Del: in docs -- https://master.php.net/note/delete/99934/in+docs
Del: other reasons-- https://master.php.net/note/delete/99934
Reject -- https://master.php.net/note/reject/99934
Search -- https://master.php.net/manage/user-notes.php