Let's say you've got an object, with a property that contains an array
with several values:

$foo->bar = array( 0=>'quiz', 1=>'quuz', 2=>'quux' );

You want to get the value of $foo->bar[1], but all you have is the
string "bar[1]" to work with (because it's a key in a submitted form),
as $key = "bar[1]";

The classic, and deeply abhorrent, way to do this is:
eval( "\$value = \$foo->$key;" );

I thought that $value = $foo->{$key} might work, but it doesn't.

Does anyone have a pattern to solve this?

--
Chris Snyder
http://chxo.com/
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to