the_oliver Posted November 19, 2010 Share Posted November 19, 2010 Hi, Im wondering if there is an easy way to get items out of an array returned by a function inside a class. A code example would be: class modDB { public function getPwdSalt() { $arr = array("salt", "password"); return $arr; } } ?> And what i would like to be able to do is something like: $modDB = new modDB; echo $modDB->getPwdSalt()->[1]; and just get returned 'password'. Is something like that possible? Many Thanks. Link to comment https://forums.phpfreaks.com/topic/219213-getting-items-out-of-array-inside-class/ Share on other sites More sharing options...
salathe Posted November 19, 2010 Share Posted November 19, 2010 The best plan is to use a two-stage process: $modDB = new modDB; $salt = $modDB->getPwdSalt(); echo $salt[1]; There are other options, ranging from awesome (but unusable) to dirty! Here's the awesome (I'll leave the dirty for someone else to post) : // Currently only available in the bleeding edge, development version of PHP // See http://wiki.php.net/rfc/functionarraydereferencing $modDB = new modDB; echo $modDB->getPwdSalt()[1]; Link to comment https://forums.phpfreaks.com/topic/219213-getting-items-out-of-array-inside-class/#findComment-1136771 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.