You are here: Strange array access problem « PHP « IT news, forums, messages
Strange array access problem

Posted by Ken Tozier on 10/26/05 07:28

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация