By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

Problem With Arrays Of Arrays, PHP 5.2.0, Windows

P: n/a
$aThePosts = array_change_key_case($_POST, CASE_LOWER);

define("CONTACT_IS_LOCAL", 0);
define("CONTACT_IS_REMOTE", 1);

/* $aWho contains an array of arrays (contact details)
* array(
* array(0, CONTACT_IS_LOCAL, "My Local Contact",
* "123 Any Street", "Suite 123",
* "Phoenix", STATE_ARIZONA, "01234-5678",
* array(800, "867-5309", "867-5309",
* "1-800-000-0000", "867-5309"),
* "www.example.com"),
* array(1, CONTACT_IS_REMOTE, ...
*/
function WhichContact() {
global $aThePosts, $aWho;

if (isset($aThePosts['idWho'])) {
$iWhich = $aThePosts['idWho'];
$iWhichCheck = $aWho[$iWhich][0];
if ($iWhichCheck == $iWhich) {
return($iWhich);
}
}
return(-1);
}

I'm running into some strange problems. Sometimes,
$aWho[$iWhich][0] turns into the index number I expect,
and sometimes it returns "array[0]".

For instance, when I insert the following code after a call
to the above.

$iWho = WhichContact();
echo("<p class=\"pc\">$iWho</p>\n");
echo("<p class=\"pc\">" . $aWho[$iWho][0] . "</p>\n");
echo("<p class=\"pc\">$aWho[$iWho][0]</p>\n");

Inside the quotes, $aWho[$iWho] turns into "array" and
the string "[0]" gets added to it. Outside of the quotes
it returns the number I expect to get back.

But then when using that inside the function to verify
that a POST variable actually matches up with the index
of the client, the comparisons fail to match.

PHP 5.2.0 (cli) (built: Nov 2 2006 11:57:36)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies

Is there a way to check the internal storage type of any
particular variable?

The POST variable is a value from an HTML

<form action="./" method="POST">
<select name="idWho">
<option value="0">Local Contact</option>
<option value="1">Remote Contact</option>
</select>
</form>

--
Jim Carlock
Post replies to the group.
Jan 29 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.