Jump to content

getting items out of array inside class.


the_oliver

Recommended Posts

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

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];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.