Array Initialization
| From: | Rich Hutchins | Date: | Sun, 13 Oct 2002 19:41:44 +0000 |
| Subject: | Array Initialization | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-22354@lists.php.net to get a copy of this message | ||
Please forgive me ahead of time, but I didn't want to subscribe to the
high-vol general list for a single question. Actually, I need this to prep
data to be passed to a db, so it's kind of close.
I have a variable number of hidden fields being passed from page A into page
B via POST. On page B, I want to take those hidden fields and turn them into
an associative array. I am able to get the data out of the $HTTP_POST_VARS
and make it look the way I want with the following code:
<!-- BEGIN POST VARS -->
<!-- { mySelect = '40', mySelect_10 = 'Miami', mySelect_20 = 'New
England',
mySelect_30 = 'Buffalo', mySelect_40 = 'New York' } -->
foreach ($HTTP_POST_VARS as $key => $value) {
if (preg_match("/mySelect_/", $key ))
{
echo("Found a match.<br>");
$stripped = substr_replace($key, "", 0, 9);
echo("Content ID=".$stripped."<br>");
echo("Its text value is: ".$value);
echo("<br><br>");
$newInfo = array($stripped => $value);
}
}
print_r($newInfo);
The resulting sample HTML data looks like this:
Found a match.
Content ID=10
Its text value is: Miami
Found a match.
Content ID=20
Its text value is: New England
Found a match.
Content ID=30
Its text value is: Buffalo
Found a match.
Content ID=40
Its text value is: New York
Array ( [40] => New York ) //here's the problem
The problem is in the $newInfo = array($strippd => $value); and it's the
last line of the sample HTML code.
What I want to achieve is:
Array ( [10] => Miami, [20] => New England, [30] => Buffalo, [40] => New
York ).
Any ideas how to get there?
Thanks in advance.