[nycphp-talk] Re: Passing array elements as... strings?
Tom Melendez
tom at supertom.com
Thu Jan 4 14:00:30 EST 2007
On 1/4/07, Nate Abele <nate at cakephp.org> wrote:
> Two solutions that come to mind are to (a) parse out the var name and
> the index from the string, or (b) submit the var name and the index
> as two separate POST vars. Any reason either of those wouldn't work?
That's what I came up with too.
$key = "bar[1]";
preg_match("/(.*)\[(\d)\]/",$key,$m);
$name=$m[1];
$index=$m[2];
$myarray=$foo->$name;
print $myarray[$index];
Very interested in other solutions. If bar comes in as an array (like
$_POST[bar][1]) you could probably use array_keys to suck out keys,
although I haven't tried it.
Tom
http://www.liphp.org
More information about the talk
mailing list