Re: SESSION array problems
| From: | tedd | Date: | Wed, 01 Oct 2008 20:23:49 +0000 |
| Subject: | Re: SESSION array problems | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-281340@lists.php.net to get a copy of this message | ||
At 2:38 PM -0500 10/1/08, Afan Pasalic wrote:
main reason - if you sort by first or last name you will lose "index". this way is index always "linked" to first/last name.Your point is well taken, but I'm not sorting this. True, the arrays have a common index, which is 0, 1, 2, 3 ...
[user_id] => Array
(
[0] => 6156
[1] => 7030
[2] => 656
)
[first_name] => Array
(
[0] => Diane
[1] => Fred
[2] => Helen
)
[last_name] => Array
(
[0] => Cable
[1] => Cago
[2] => Cahalan
But the data is relational, such as:
Diane Cable has user id 6156.
I collected the data like this (in a loop):
$_SESSION['user_id'][] = $value;
$_SESSION['first_name'][] = $first_name;
$_SESSION['last_name'][] = $last_name;
Doing this is fine -- the index is automatic.
I thought I could retrieve the data by using:
$num_users = count($_SESSION['user_id']); // <--- this works (correct $num_users)
for ($i = 0; $i < $num_users; $i++)
{
$last_name = $_SESSION['last_name'][$i];
$first_name = $_SESSION['first_name'][$i];
echo("<tr><td>$last_name</td><td>$first_name</td></tr>");
}
But that doesn't work. What's really odd is only the first loop works.
PLUS, a dump of the SESSION arrays done just before the loop does produce what's shown above. So, the data is there, I'm just not retrieving it.
There's something here that I'm not understanding. I always seem to have problems with Multidimensional Arrays -- I think it's my dyslexia kicking in.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com