this is a script which echo formatted value from array . I want to add full stop at the end of array values and put commas in between.
This script works but need advanced techniques in php
$array=array("One"=>"Value one",
"Two"=>"Va开发者_开发百科lue Two",
"Three"=>"Value Three");
$store =''; //To store formatted value
foreach($array as $key=>$val){
if($key=='Three') // Check key value to assign full stop or comma
$comma=".";
else
$comma=",";
$store .=$val.$comma;
}
echo $store; //Ans: Value one,Value Two,Value Three.
Using implode
will make this so much easier:
echo implode(',', $array) . '.';
精彩评论