<?php
$lukujono = $_GET['lukujono']; // Can't touch this line
$lukutaulukko = explode(',',$lukujono); // Can't touch this line
$pisteet = $lukujono; # my code
$summa = array_sum($lukutaulukko); # my code
$keskiarvo = ($summa/count($lukutaulukko)); # my code
echo "Pisteet olivat: $pisteet\n"; // Can't touch this line
echo "Pisteiden summa: $summa\n"; // Can't touch this line
echo "Pisteiden keskiarvo: $keskiarvo"; // Can't touch this line
?>
所以一切正常,但我必须从$ pisteet中删除逗号?我希望它显示1 2 3 4 5等。但现在它是1,2,3,4,5。非常感谢你&lt; 3
答案 0 :(得分:0)
$ pisteet 看起来像字符串而不是数组,因为您正在回复。
您可以使用 str_replace()
试试这个
echo "Pisteet olivat: ".str_replace(","," ",$pisteet)."\n";
如果您无法触及上面的线路,请尝试此操作。
$pisteet = str_replace(","," ",$lukujono);
输出
Pisteet olivat: 1 2 3 4 5
查看实时示例here
答案 1 :(得分:0)
您可以使用str_replace
用法:string return = str_replace($find, $replace, $subject);
$pisteet = "1,2,3,4,5";
Echo str_replace(",", " ", $pisteet);