开发者

how to simplify this script or use more advanced built-in function

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) . '.';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜