Jump to content

[SOLVED] Array problem


bpgillett

Recommended Posts

hi.  echoing a string in my array from $_POST by numeric position returns nothing; however, referencing it by variable name works.  is there a problem referencing an array created from $_POST by numeric position?  if so, any way around this?  thanks.

works:

$post = $_POST;
echo $post['q1'];

doesn't work:

$post = $_POST;
echo $post[0];

Link to comment
https://forums.phpfreaks.com/topic/47315-solved-array-problem/
Share on other sites

$_POST is an associative array whose keys are the names of form fields. If you want to process it as an indexed array you can

$post = array_values($_POST);

 

However, if the only reason to do this is to loop through all the values then you can use

 

foreach ($_POST as $value) {
    echo $value;
}

Link to comment
https://forums.phpfreaks.com/topic/47315-solved-array-problem/#findComment-230827
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.