Monday, 19 August 2013

Returning variable keys via public static function within a class

Returning variable keys via public static function within a class

I've been having a bit of trouble doing, what I believe is possible
(although I'm not sure). What I do know is that what I'm attempting to do
is a bit nonsensical and not the best way to do it.
class myClass {
public static function myData() {
$data = [
'index' => 'key';
];
}
}
What I'm attempting to do is to return the value of key via static
function. I've been trying to view (via var_dump()) what's inside of my
static function (myClass::myData();) however, it comes up NULL.
I'm still pretty new to PHP, but I've been working around trying to find
things to work on (even if they're pretty nonsensical) to get better
acquainted. If this is at all possible, I'd like to complete it this way.
I've been searching for an answer to this for about 2 hours, so yes, I
have looked around to try and fix this issue myself first, but to no
avail.
Additionally, if this simply can't be done, what is the best way to do
something like this? I appreciate any responses!

No comments:

Post a Comment