473,513 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to display name instead of 'Array' when displaying multidimensional array in form

I'm having a problem receiving the full amount of information i need on a grocery order from that i'm accessing inputted values using form to mail in php.

a snippet of my form looks like this:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form action="...php" method=POST...
  4. <tr>
  5.               <th scope="col">Beer:</th>
  6.               <th scope="col"><input type="text" name="BeerandWine[Beer][]" /></th>
  7.               <th scope="col"><input type="text" name="BeerandWine[Beer][]" /></th>
  8.               <th scope="col"><input type="text" name="BeerandWine[Beer][]" /></th>
  9.               </tr>
  10.             <tr>
  11.               <th scope="col">Wine:</th>
  12.               <th scope="col"><input type="text" name="BeerandWine[Wine][]" /></th>
  13.               <th scope="col"><input type="text" name="BeerandWine[Wine][]" /></th> 
  14.               <th scope="col"><input type="text" name="BeerandWine[Wine][]" /></th>      
  15.               </tr>
  16.             <tr>
  17.               <th scope="col">Liquor:</th>
  18.               <th scope="col"><input type="text" name="BeerandWine[Liquor][]" /></th>
  19.               <th scope="col"><input type="text" name="BeerandWine[Liquor][]" /></th>
  20.               <th scope="col"><input type="text" name="BeerandWine[Liquor][]" /></th>
  21.               </tr>
  22. ...</form>
  23. </body>
  24. </html>
There are many of these, it's a full grocery list.

here is my php code to send it to my email:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. foreach($_POST as $key){
  3.          if (is_array($key)){
  4.          $message.="Category: $key\n";
  5.             foreach($key as $row){
  6.                $message.="Item: $row\n";
  7.             foreach($row as $col => $val){
  8.             $val = stripslashes($val);
  9.                   $message.="$col: $val\n";
  10.             }
  11.          } 
  12.        }
  13. }
  14. ?>
And here is what shows up in my email:

Category: Array
Item: Array
0: Stella
1: 6 pack
2: Cold
Item: Array
0: Merlot
1: 750ml
2:
Item: Array
0: Whiskey
1:
2: With cup


I'ts really a very handy script, except i can't seem to gather anything but 'array' from $key and $row.
How can I make the index name of the nested array display in my email, instead of 'array'. Keeping in mind I have a few hundred inputs.

This is how i want it to look:

Category: BeerandWine
Item: Beer
0: Stella
1: 6 pack
2: Cold
Item: Wine
0: Merlot
1: 750ml
2:
Item: Liquor
0: Whiskey
1:
2: With cup

and i also want to have:
Type/Brand:, Quantity:, Notes:
instead of:
0:, 1:, 2:
and not display the empty values, but those I could probably find on my own after I solve this...I've been searching for a solution to this for days. Any help?
Oct 25 '10 #1
1 1559
code green
1,726 Recognized Expert Top Contributor
To print out an array you need print_r($array).
I find formating is much tidier. Use
Expand|Select|Wrap|Line Numbers
  1. '<pre>Data '.print_r($array,1).'</pre>'
Note the '1' as second parameter in print_r.
You will still get the word 'array'. The only way I have found to remove this is with str_replace('Array','',string)
Oct 25 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1919
by: bogdan.maxim | last post by:
I have the folowing structure defined in a C++ COM Project: struct a { DOUBLE a1; //This is the problem DOUBLE a2; DOUBLE a3; };
1
4151
by: @ nospam.com | last post by:
Hi, If Im using Jagged arrays, the following is possible: int arr = new int for(int i=0; i<10; i++) { arr = new int; }
2
3422
by: xhunga | last post by:
I have try a new version of my work. I have put the sizes of the matrix into the matrix. A = number of rows A = number of columns The first element of the matrix is A instead of A. You...
4
5510
by: Gregory.A.Book | last post by:
I'm working with displaying and manipulating very large image sets. The program handles anything from 2D images to 4D RGB volumes in a time-series. I've been using dynamically allocated arrays to...
5
10324
by: TS | last post by:
is there some code somewhere that does this? i have a jagged array that is not jagged, it has an equal number of rows and columns in each array so it should convert but want to get the code to do...
2
1632
by: mareharbor | last post by:
Can anyone help me to change this array to a multidimensional array with 1 more components i want to add another "column" to the array with a similiar specification of "cell.Offset(0, -2).Value". So,...
2
2352
by: phattymatty | last post by:
I am having trouble getting this loop to do what I would like it to. I need to display information from a multidimensional array in order. The order has already been sorted in the array using a...
1
1742
by: shailajaAdiga | last post by:
Hi All, there are 4 different categories which each month will bw updated. In each category(source),there are many editions. I have to display 6months updates. its like one is month array which...
4
2497
Jezternz
by: Jezternz | last post by:
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it...
9
4473
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.