Jump to content

Baffled by Undefined Index in Simple Array: Please Help!


somedude084

Recommended Posts

Hello. I have a form which posts an array to this script. However, I can't seem to access the values in the array; I keep getting an undefined index. Something is not right, but the code is so simple! What am I missing?

 

print_r($_POST['Item'][0]);

// Output is: Array ( ['Quantity'] => 1 ['Item_id'] => 5 )

echo $_POST['Item'][0]['Quantity'];

// Output is: Notice: Undefined index: Quantity in /Volumes/Macintosh HD/Sites/.../hal/item/reconcile.php on line 30

 

:wtf:

Link to comment
Share on other sites

Thanks for the response, but not sure that I follow. Perhaps my syntax is wrong, but there has to be some way to access values from an array containing an array. As shown by the code example, this is a multi-dimensional array, so $_POST['Item'][0] (the "top-level" array's item) itself contains an array with key-value pairs (as shown by the first line of output): what I am trying to do is access the value related to the 'Quantity' key in that "sub-array."

 

You seem to imply that multi-dimensional arrays are not possible? This is not per my understanding. Can anyone help? Much appreciated!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.