Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How would I print this array?

Here's my array when I do a var_dump:

C:\wamp64\www\adm\jquery_post.php:9:
array (size=2)
  'comparison_value' =>
    array (size=1)
      0 => string 'asdf' (length=4)
  'between_value' =>
    array (size=1)
      0 => string 'fghj' (length=4)

I want to be able to print out:

comparison_value = asdf
between_value=fghi

How?
Avatar of Norie
Norie

Something like this perhaps.
foreach ( $yourarray as $key => $value )
{
echo "$key = $value\n";
}

Open in new window

Avatar of Bruce Gust

ASKER

That gives me this:

#TimeMemoryFunctionLocation
Call Stack
( ! ) Notice: Array to string conversion in C:\wamp64\www\adm\jquery_post.php on line 13
10.0009414008{main}( )...\jquery_post.php:0
comparison_value = Array
#TimeMemoryFunctionLocation
Call Stack
( ! ) Notice: Array to string conversion in C:\wamp64\www\adm\jquery_post.php on line 13
10.0009414008{main}( )...\jquery_post.php:0
between_value = Array
BTW: Here's the form from which all of this is coming:

<form action="jquery_post.php" method="Post">
   <input type="text" name="criteria[comparison_value][]"><br>
   <input type="text" name="criteria[between_value][]">
   <input type="submit" value="submit">
</form>

Not the way I usually put a form together, but that's the infrastructure I'm dealing with and that's what results in the "var_dump" you see above.

Thanks!
What's the array name?
Here's the code:

<?php
   var_dump($_POST['criteria']);
   echo "<br><br>";
   foreach ( $_POST['criteria'] as $key => $value )
      {
      echo "$key = $value\n";
      }
   ?>

The array would be $_POST['criteria']
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That did it!

Thanks!
Bruce

Glad that worked, curious about the second set of [] - is there a reason for them?

Without them the code you posted should work.
Couldn't tell you. I'm coming in after the fact and just trying to make things work...!
No, problem.:)