Re: More array syntax
| From: | Greg Beaver | Date: | Sun, 09 Mar 2003 05:10:44 +0000 |
| Subject: | Re: More array syntax | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138831@lists.php.net to get a copy of this message | ||
Hi John,
foreach ($var as $key => $value)
{
if (!$key) {
$$key = filter_string($key.': ',$line);
}
}
Regards,
Greg
--
phpDocumentor
http://www.phpdoc.org
John Taylor-Johnston wrote:
I have an array $var (see structure below), which contains AN, AU, TI, PY ... etc. (28 in total - no teasing.) How can access these keys so I can do this: foreach key in $var until $var.length { if(!$something){$something = filter_strings("something: ",$line);} } So I can avoid doing this 28 times: if(!$AN){$AN = filter_strings("AN: ",$line);} if(!$AU){$AU = filter_strings("AU: ",$line);} if(!$TI){$TI = filter_strings("TI: ",$line);} if(!$PY){$PY = filter_strings("PY: ",$line);} ... and this 28 times. if($AN) {DisplayLine('AN',$AN);} if($AU) {DisplayLine('AU',$AU);} if($TI) {DisplayLine('TI',$TI);} if($PY) {DisplayLine('PY',$PY);} ... $var = array ( 'AN' => array ( 'Description' => 'ERIC_NO: (AN)','Input' => 'EricAN', 'Select' => 'SelAN', 'Option' => 'AN', 'Selected' => 'AN «Annotation»'), 'AU' => array ( 'Description' => 'AUTHOR: (AU)','Input' => 'EricAU', 'Select' => 'SelAU', 'Option' => 'AU', 'Selected' => 'AU «Author»'), 'TI' => array ( 'Description' => 'TITLE: (TI)','Input' => 'EricTI', 'Select' => 'SelTI', 'Option' => 'TI', 'Selected' => 'TI «Title»'), 'PY' => array ( 'Description' => 'PUBLICATION_DATE: (PY)','Input' => 'EricPY', 'Select' => 'SelPY', 'Option' => 'YR', 'Selected' => 'YR «Year of Publication»'), 24 more to go. )