Last active
October 22, 2016 19:35
-
-
Save Committing/8b80ebd6e9d56e0b026887de5025d790 to your computer and use it in GitHub Desktop.
Answer for question on StackOverflow: http://stackoverflow.com/questions/39983925/php-oop-echo-ing-a-single-variable-from-within-a-class/39983994#39983994
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Language { | |
public $language = ''; | |
public $phrases = array( | |
'UK' => array( | |
'hello' => 'Ello gov\'na ', | |
'goodbye' => 'Good day!' | |
), | |
'AUS' => array( | |
'hello' => 'Alight mate? ', | |
'goodbye' => 'See ya later, mate' | |
) | |
); | |
public function __construct($language = 'UK') | |
{ | |
$this->language = $language; | |
} | |
public function say($phrase_key = 'hello') | |
{ | |
return $this->phrases[$this->language][$phrase_key]; | |
} | |
} | |
$language = new Language('AUS'); | |
echo $language->say('goodbye'); | |
// See ya later, mate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment