You are here: Re: newbie question: using $_POST inside of array parameters? « PHP Programming Language « IT news, forums, messages
Re: newbie question: using $_POST inside of array parameters?

Posted by mootmail-googlegroups on 08/30/06 13:52

Norman Peelman wrote:
> <kurrent@gmail.com> wrote in message
> news:1156886642.624061.318070@m73g2000cwd.googlegroups.com...
> > I am relatively new to PHP and just have a question regarding $_POST to
> > get a value passed via a form to be included of the parameter of an
> > array I am using:
> >
> > eg.
> >
> > <?
> >
> > $a array = ("1", "2", "3");
> >
> > echo "<form method=POST>
> >
> > <select name=b size=1>
> > <option value=1>number1</option>
> > <option value=2>number2</option>
> > <option value=0>number3</option>
> > </select>
> >
> > <input type=submit name=Submit>
> >
> >
> > </form>";
> >
> > echo "$a[$b]";
> >
> >
> > Since I have a global variables turned off, and would like to keep
> > learning with them off, I am stumped on to get that value passed
> >
> >
> > >From my understanding, I see that $_POST[b] would successfully retrive
> > the value of the $b variable. So i've tried many variants on the syntax
> > but no luck (e.g. "$a[$_POST[b]]) etc...
> >
> > any help is much appreciated :) thanks!
> >
>
> How about: echo "{$a[$_POST['b']]}";
>
> Norm

Building upon that advice, there is a limitation when using
double-quoted strings in PHP which you should be aware of.

Double-quoted strings will be parsed for variables, however only of the
simplest types. Anything more complex needs to be encased in curly
braces { } in order to be evaluated.

So while you can do:
echo "$foo"; \\evaluates variable $foo
You cannot do:
echo "$foo['a']";
echo "$foo[$x]";
echo "$foo->x";

Instead, you must do:
echo "{$foo['a']}";
echo "{$foo[$x]}";
echo "{$foo->x}";

 

Navigation:

[Reply to this 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

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