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?
PHP

Avatar of undefined
Last Comment
Norie
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
Bruce Gust
Flag of United States of America image

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
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

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!
Avatar of Norie
Norie

What's the array name?
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

That did it!

Thanks!
Avatar of Norie
Norie

Bruce

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

Without them the code you posted should work.
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

Couldn't tell you. I'm coming in after the fact and just trying to make things work...!
Avatar of Norie
Norie

No, problem.:)
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo