Jump to content
Fórum Script Brasil
  • 0
Sign in to follow this  

como declarar variaveis de outra pagina num array?


construir um script em PHP que a partir de um formulário HTML, leia 10 números, armazene em um vetor e os imprima na ordem inversa a ordem de leitura.

Eu fiz assim no htm:

<form name="f" action="exemplo10.php" method="POST">
Digite o 1 numero: <input type="text" name="n1" size="5"><br />
Digite o 2 numero: <input type="text" name="n2" size="5"><br />
Digite o 3 numero: <input type="text" name="n3" size="5"><br />
Digite o 4 numero: <input type="text" name="n4" size="5"><br />
Digite o 5 numero: <input type="text" name="n5" size="5"><br />
Digite o 6 numero: <input type="text" name="n6" size="5"><br />
Digite o 7 numero: <input type="text" name="n7" size="5"><br />
Digite o 8 numero: <input type="text" name="n8" size="5"><br />
Digite o 9 numero: <input type="text" name="n9" size="5"><br />
Digite o 10 número: <input type="text" name="n10" size="5"><br />

<input type="submit" value="Imprimir Inverso">

e assim no php:

$x= array();

for ($i=0; $i<=9); $i++)
$x[$i] = $_POST["n".$i+1];
echo " $x[$i] ";
echo "<br/>________________<br/>";

for ($i=10; $i>=0; $i--)
echo $x [$i]"<br/>";
// echo " $x[$i] ";


só q não ta funcionando, o q pode ser?

Share this post

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

se quer imprimir o inverso só faça isso:

for ($i=10; $i>=0; $i--){
    echo $_POST["n".$i]."<br/>";

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...