multi dimensional arrays
| From: | Scott Mebberson | Date: | Fri, 15 Dec 2000 02:36:00 +0000 |
| Subject: | multi dimensional arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-30437@lists.php.net to get a copy of this message | ||
Hi Guys,
I am doing error checking here and have developed the following code to add
errors to and $errors array.
$errors[0] = "<span class=error>The following errors have
occured:</span><br> <br>\n\n";
$errors[count($errors)] = This is an error that has occured.<br>\n";
$errors[count($errors)] = This is another that has occured.<br>\n";
This works fine, I then check to see if there are any errors and if so print
them out:
if (!$errors[1]) {
// continue with code execution
} else {
$num_errors = count($errors);
for ($idx = 0; $idx < $num_errors; ++$idx) {
echo ("$errors[$idx]");
}
echo ("<br>\nPlease click <a href=\"#\"
onClick=\"backButton();\">here</a> to fix these problems");"";
}
But I want to do the same thing for a multidimensional array with the two
upper types of arrays being critical and non-critical.
I know I can make mutlidimensional arrays by the following:
$errors = array("non-critical" => array("First non-critical
error","Second
non-critical error"), "critical" => array("first Critical Error",
"Second
Critical Error", "Third Critical error"));
But I need to know how to add the array (and the currect sub-array) as I
wish, like in the first example.
Thanks for any help.
Scott.