I ran this code and it worked
<!DOCTYPE html>
<html>
<body>
<?php
$pizza = "slice1 slice2 slice3 slice4 slice5 slice6";
$slices = explode(" ", $pizza);
echo " $slices[0] <br> " ;
echo $slices[1];
?>
</body>
</html>
and when i run this code it worked the same way
<!DOCTYPE html>
<html>
<body>
<?php
$pizza = "slice1 slice2 slice3 slice4 slice5 slice6";
$x = substr_count($pizza , ' ')+1 ;
echo "$x <br>";
?>
</body>
</html>
I don't know, maybe I made a string integer error, I thought I should define it from the beginning, so I searched this.
<?php
$x = 5985;
var_dump(is_int($x));
$x = 59.85;
var_dump(is_int($x));
?>
finally i wrote the following code but it gives me error
<!DOCTYPE html>
<html>
<body>
<?php
settype($x, "integer");
settype($y, "integer");
$pizza = "slice1 slice2 slice3 slice4 slice5 slice6";
$slices = explode(" ", $pizza);
$y = substr_count($pizza , ' ')+1
for( $x = 0 ; $x <= $y ; $x++ ) {
echo $slices[$x] <br> ;
}
?>
</body>
</html>
PHP Parse error: syntax error, unexpected 'for' (T_FOR) in /home/6TZO55/prog.php on line 17
What I have tried:
<!DOCTYPE html>
<html>
<body>
<?php
settype($x, "integer");
settype($y, "integer");
$pizza = "slice1 slice2 slice3 slice4 slice5 slice6";
$slices = explode(" ", $pizza);
$y = substr_count($pizza , ' ')+1
for( $x = 0 ; $x <= $y ; $x++ ) {
echo $slices[$x] <br> ;
}
?>
</body>
</html>