SneakyDave
03-26-2001, 01:02 AM
OK, here's something else that I can't seem to figure out. I've read the PHP manual for examples or answers, but for some reason, nothing is working.
I have a 2 dimensional array like this (this is an example from php.net):
<?
$users = array(
"djuan" => array(
[nbsp][nbsp] "firstname" => "Don",
[nbsp][nbsp] "lastname" => "Juan",
[nbsp][nbsp] "age" => "102",
[nbsp][nbsp] "weight" => "100"
),
[nbsp]"jordan23" => array(
[nbsp][nbsp][nbsp][nbsp]"firstname" => "Michael",
[nbsp][nbsp][nbsp][nbsp]"lastname" => "Jordan",
[nbsp][nbsp][nbsp][nbsp]"age" => "36",
[nbsp][nbsp][nbsp][nbsp]"weight" => "225"
)
);
?>
OK, I have an 2 dimensional array called $users. I can print out what it looks like by doing this:
<?
while ( list($username, $subarray) = each($users) ) {
[nbsp][nbsp]echo "Username: $username: ";[nbsp][nbsp]
[nbsp][nbsp]echo "<ul>";
[nbsp][nbsp]while ( list($key, $val) = each($subarray) ) {
[nbsp][nbsp][nbsp][nbsp]echo " $key : $val\n";
[nbsp][nbsp]}
[nbsp]echo "[/list]";
}
?>
Now, the simple problem is, how would I add more names while processing? I tried it this way:
$users = array(
"sd" => array(
[nbsp][nbsp] "firstname" => "sneaky",
[nbsp][nbsp] "lastname" => "dave",
[nbsp][nbsp] "age" => "666",
[nbsp][nbsp] "weight" => "200"
),
But that doesn't work of course because it re-initializes the array. I don't see how you'd insert more values into the table other than at initialization. Would it look something like this?
$users["sd"]["firstname"] = "sneaky";
$users["sd"]["lastname"] = "dave";
$users["sd"]["age"] = "666";
$users["sd"]["weight"] = "200";
[nbsp]
I have a 2 dimensional array like this (this is an example from php.net):
<?
$users = array(
"djuan" => array(
[nbsp][nbsp] "firstname" => "Don",
[nbsp][nbsp] "lastname" => "Juan",
[nbsp][nbsp] "age" => "102",
[nbsp][nbsp] "weight" => "100"
),
[nbsp]"jordan23" => array(
[nbsp][nbsp][nbsp][nbsp]"firstname" => "Michael",
[nbsp][nbsp][nbsp][nbsp]"lastname" => "Jordan",
[nbsp][nbsp][nbsp][nbsp]"age" => "36",
[nbsp][nbsp][nbsp][nbsp]"weight" => "225"
)
);
?>
OK, I have an 2 dimensional array called $users. I can print out what it looks like by doing this:
<?
while ( list($username, $subarray) = each($users) ) {
[nbsp][nbsp]echo "Username: $username: ";[nbsp][nbsp]
[nbsp][nbsp]echo "<ul>";
[nbsp][nbsp]while ( list($key, $val) = each($subarray) ) {
[nbsp][nbsp][nbsp][nbsp]echo " $key : $val\n";
[nbsp][nbsp]}
[nbsp]echo "[/list]";
}
?>
Now, the simple problem is, how would I add more names while processing? I tried it this way:
$users = array(
"sd" => array(
[nbsp][nbsp] "firstname" => "sneaky",
[nbsp][nbsp] "lastname" => "dave",
[nbsp][nbsp] "age" => "666",
[nbsp][nbsp] "weight" => "200"
),
But that doesn't work of course because it re-initializes the array. I don't see how you'd insert more values into the table other than at initialization. Would it look something like this?
$users["sd"]["firstname"] = "sneaky";
$users["sd"]["lastname"] = "dave";
$users["sd"]["age"] = "666";
$users["sd"]["weight"] = "200";
[nbsp]