PHP Program
PHP Program
<!DOCTYPE html>
<html>
<body>
<?php
$txt1 = "Sum of x and y is:";
$x = 1234;
$y = 4321;
echo "<h3>" . $txt1 . "</h3>";
echo $x + $y;
?>
</body>
</html>
Output
Sum of x and y is:
5555
Using recursion:
Example
<!DOCTYPE html>
<html>
<body>
<?php
function fibonacci($x,$y)
{
$c = $x + $y;
return $c;
}
$a = 0;
$b = 2;
echo "Fibonacci series with the first 2 numbers as 0 and 2 is: ";
echo "$a, $b";
for ($i = 0; $i < 26; $i++)
{
echo ", ";
echo fibonacci($a,$b);
$z = fibonacci($a,$b);
$a = $b;
$b = $z;
}
?>
</body>
</html>
Output
Fibonacci series with the first 2 numbers as 0 and 2 is:
0, 2, 2, 4, 6, 10, 16, 26, 42, 68, 110, 178, 288, 466, 754, 1220,
1974, 3194, 5168, 8362, 13530, 21892, 35422, 57314, 92736, 150050,
242786, 392836
PHP Program To Combine The Array Elements Into A String With Given Delimiter
<!DOCTYPE html>
<html>
<body>
<?php
$arr = array("Have", "Courage.", "Live", "Free.");
print_r (implode(" ",$arr));
?>
</body>
</html>
Output
Have Courage. Live Free.