Re: multi dimensional arrays

From: Date: Fri, 15 Dec 2000 05:00:00 +0000
Subject: Re: multi dimensional arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-30449@lists.php.net to get a copy of this message
On Fri, 15 Dec 2000, Scott Mebberson wrote: > 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>&nbsp;<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"; (snip) > 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. It all works the same way. $errors['non-critical'][count($errors['non-critical'])] ought to work, but I'd just assume append, rather than go to the trouble. This is valid: $errors[] = "<span class=error>The following errors have occured:</span><br>&nbsp;<br>\n\n"; $errors[] = This is an error that has occured.<br>\n"; $errors[] = This is another that has occured.<br>\n"; And by extension, so is this $errors['non-critical'][] = "<span class=error>The following errors have occured:</span><br>&nbsp;<br>\n\n"; $errors[''non-critical][] = This is an error that has occured.<br>\n"; $errors['non-critical'][] = This is another that has occured.<br>\n"; Matt

« previous php.general (#30449) next »