Reputation:
here is my code, I want to print single space between each array element problem i am facing is m getting space on every element but there is space for 1st element also
$handle = fopen ("php://stdin","r");
fscanf($handle,"%d",$n);
$arr_temp = fgets($handle);
$arr = explode(" ",$arr_temp);
array_walk($arr,'intval');
for($i=sizeof($arr);$i>=0;$i--)
{
echo $arr[$i]." ";
}
?>
my output is " 2 3 4 1" i want "2 3 4 1" there is space in the 1st element.
Upvotes: 1
Views: 1414
Reputation: 672
ltrim will remove spaces from left side
echo ltrim($arr[$i])." ";
Upvotes: 0
Reputation: 6223
use ltrim()
it will remove space from left end
read documentation for further details
Upvotes: 1