1
這是一個腳本,它從數組中回顯格式化的值。我想在數組值的末尾添加句號,並在逗號之間插入逗號。如何簡化這個腳本或使用更高級的內置函數
這個腳本工作,但需要在PHP
$array=array("One"=>"Value one",
"Two"=>"Value 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.