When I print_r($_POST) to determine what's being posted from my form, I get this:

Array ( [name] => Array ( [0] => Joe [1] => [2] => [3] => [4] => [5] => ) [animal] => Array ( [0] => Dog  [1] => Cat [2] => [3] => [4] => [5] => ) [submit] => Validez )

Then, I array_combine to (duh) combine the arrays, and I get this:

Array ( [Joe] => Dog [] => ) 

I thought I'd get this:

Array ( [Joe] => Dog [] => Cat) 

Am I supposed to, or have I misunderstood array_combine? How can I get this working the way I expected it to?

    I think you misunderstood what array_combine does:

    Creates an array by using one array for keys and another for its values

    Perhaps you wanted array_merge....

    Unfortunately you'd have to manually loop through your merged array to remove the empty elements.

      When I print_r($_POST) to determine what's being posted from my form, I get this:

      I find its more helpful to use GET for testing purposes, then you will see everything in the url, both variable names and values. When you see that things are working as they should etc you change it back to POST.

        Umm... using $GET to access things in a form that were "post"-ed to a PHP page wouldn't help. You'd need to use $REQUEST to see both GET and POST variables. Not sure how $_GET would help you in that case 🙁

          bpat1434 wrote:

          Umm... using $GET to access things in a form that were "post"-ed to a PHP page wouldn't help. You'd need to use $REQUEST to see both GET and POST variables. Not sure how $_GET would help you in that case 🙁

          You missunderstand. Instead of <form method="post"> you use <form method="get"> and $GET when testing, then change back to <form method="post"> and $POST when the script is working or you are finished debugging. A bit extra work to replace code, but i find it easier to see what the form is passing along.

            Okay, but you could just as easily use $_REQUEST and leave the form alone as well 😉

              From Predefined variables

              $_REQUEST

              Variables provided to the script via the GET, POST, and COOKIE input mechanisms, and which therefore cannot be trusted.

              So i have stopped using REQUEST. But you are correct you could just put REQUEST instead and not have to change anything in the "form action script", but the form method still needs to be changed since my point was to get the different variables and values up in the url so its easier to see whats happening.

              Edit: perhaps not easier, but a different method. Anyway when doing print_r() i find its better to read if you put <pre> tags around it, atleast on large arrays.

                Write a Reply...