Reply to Re: [PHP] Array - partical path to the array's path....

Your name:

Reply:


Posted by "Scott Fletcher" on 09/28/05 01:03

:-)

"Mike Dunlop" <miked@m80im.com> wrote in message
news:D2C59439-01E0-4153-B5AD-28CFC97D8C19@m80im.com...
> My bad - that doesn't work - that came off the top off my head. It
> sure did look sexy though, no ?
>
> - MD
>
>
> >> echo ${"array".$prefix};
> >>
> >
> > really? did you test that?
> > doesn't work when I do it (the second expression does
> > - but doesn't answer the OPs question actually imho the
> > answer is not eval() either, because its slow and a security
> > headache):
> >
> >
> > $array = array();
> > $array["col3"]["col2"] = "Test #2";
> > $prefix = "[\"col3\"][\"col2\"]";
> > echo ${"array".$prefix}, ${"array"}["col3"]["col2"];
> >
> >
> >
> > -----------------------------
> > try something like this instead?:
> > (code has been tested)
> >
> > function getVal($arr, $path)
> > {
> > $retval = null;
> >
> > if (!is_array($arr) || empty($arr) ||
> > !is_array($path) || empty($path)) {
> > return null;
> > }
> >
> > while (count($path)) {
> > $key = array_shift($path);
> > if (!isset($arr[ $key ])) {
> > return null;
> > }
> > $retval = $arr[ $key ];
> > $arr =& $arr[ $key ];
> > }
> >
> > return $retval;
> > }
> > $ra = array();
> > $ra["col3"]["col2"] = "Test #2";
> > $path = array("col3","col2");
> > echo getVal($ra, $path);
> >
> >
> >
>
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация