-1
<form  name="form1" method="post" action="test2.php"> 
    <input type="checkbox" name="checkbox1">
    <input type="text" name="textbox1">
    <input type="submit" name="submit"> 
</form>


 <?php
    echo print_r($_POST);
 ?>

The code shows Array () 1 or Array ( [checkbox1] => on [textbox1] => asf [submit] => submit ) 1.

I don't understand why does the array always follows the number 1.

When I change POST method to GET method, the same thing happen.

When I use another Array to store the value of $_POST, the same thing happen again!

<?php
    $temp = $_POST;
    if (isset($_POST['textbox1']))
    $temp = "textbox1='{$temp['textbox1']}'";

    textbox1='asdf'1
    Array ( [textbox1] => asdf [submit] => submit) 1
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
Steve
  • 45
  • 9
  • 1
    There must be something in your page outputting the '1' Have you checked for hidden characters or other markup? – Jay Blanchard Feb 23 '17 at 13:56
  • add die() after var_dump(use var_dump instead print_r) and show ouput – bxN5 Feb 23 '17 at 13:58
  • 1
    If you don't do a `print_r` do you still see that extra `1` outputted? – apokryfos Feb 23 '17 at 13:58
  • problem is `echo` – Masivuye Cokile Feb 23 '17 at 14:11
  • If an answer solved your problem, consider accepting the answer. Here's how http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. You'll earn points and others will be encouraged to help you. *Welcome to Stack!* – Jay Blanchard Feb 23 '17 at 14:21

2 Answers2

4

echo and print are similar, this is like doing echo echo ($_POST); to give you an example (which would give you an error).

Remove echo and leave only print_r($_POST);.

Also, check this link on differences between echo, print and print_r.

Community
  • 1
  • 1
Condorcho
  • 503
  • 4
  • 12
  • To be exact: `print_r` function (without second parameter set) prints its argument directly to stdout. It **ALSO** returns a value (`true`). So, what you were doing, you were first printing out variable contents to stdout, and THEN echo'ing return value of `print_r` function (`true`, mapped to `1` by `echo`). – Tomasz Struczyński Feb 23 '17 at 16:44
1
<form  name="form1" method="post" action="test2.php"> 
    <input type="checkbox" name="checkbox1">
    <input type="text" name="textbox1">
    <input type="submit" name="submit"> 
</form>


 <?php
    print_r($_POST);  // Remove echo 
 ?>
tushar
  • 161
  • 1
  • 2