I have a problem and it is that I have a box to enter a number and based on that the php program has to do a fibonacci as entered but the problem is that I don't know how to do it. Can somebody help me? I'd be really grateful
<form action="funciones.php" method="post" name="myForm">
Introduce Numero<br>
<input type="int" name="numero" value=" "><br>
<input type="radio" id="age1" name="fib" >
<label for="age1">Fibonacci</label><br>
<input type="radio" id="age2" name="Fac" >
<label for="age2">Factorial</label><br>
<input type="radio" id="age3" name="Sumax" >
<label for="age3">Suma xifres</label><br><br>
<input type="radio" id="age4" name="Capicua" >
<label for="age4">Capicua</label><br><br>
<input type="submit" value="Submit">
</form>
<?php
if(isset($_POST['fib'])){
function fibonacci ($num){
$numero=0;
$j1=0;
$j2=1;
echo $j1.' '.$j2.' ';
while($numero < $num){
$j3=$j2+$j1;
echo $j3.' ';
$j1=$j2;
$j2=$j3;
$numero=$numero + 1;
}
}
fibonacci('fib');
}
?>
When you execute the function you have to pass it the variable that you want to act as $num. Your code should be like this.
In this case, the variable $_POST['fib'] will act as $num in your function.
As long as you specify the need for a variable when you build the function:
You will have to give it a value that occupies that function, in your case you had entered:
So you were passing a string to your function when it should be an int.