Re: Strange array access problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ken Tozier wrote:
I'm having a major problem with what seems, on it's face, to be a really basic array function.

What happens is on the browser end, I've written some javascript code that packages up javascript variables in native PHP format and sends the packed variables to a PHP script on the server via a POST and XMLHTTP. On the server end, the PHP script grabs the packed variables out of the $_POST, strips slashes and uses the "unserialize" command.

Here's the function that gets the post data
$unpacked_data    = GetDataFromPOST();

And here's a var_dump of $unpacked_data as it appears in the browser
 array(1) { ["handler"]=>  array(1) { ["0"]=>  string(9)  "databases" } }

I'm able to get the "handler with no problem like so:
$parts    = $unpacked_data['handler'];

Which yields the following var_dump
array(1) { ["0"]=>  string(9) "databases" }

Here's where the problem starts. I've had no luck whatsoever trying to get items of $parts. I've tried all of the following and each of them return NULL

$part_1 = $parts[0];
$part_1 = $parts['0'];
$part_1 = $parts["0"];
$part_1 = $parts[48]; <- ASCII character for zero

In desperation, I also tried this

foreach($parts as $key => $value)
{
        var_dump($key);
        // => string(1) "0"
        var_dump($value);
        // => string(9) "databases"

        $parts_1 = $parts[$key];
        // => NULL;
}

But no luck

I also checked the type and size of the key like so
foreach($parts as $key => $value)
{
       echo gettype($key);
        // => string

        echo sizeof($key);
        // => 1
}

Anyone have any insights as to what the heck is going on here? This should be a piece of cake but It's stopped me cold for a full day and a half

Thanks for any help

Ken


Why the serialize/unserialize()? Don't serialize() on the client's and see what happens if you just print_r($_POST) as received?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux