So I have some arrays
$array_1 = Array('one','two','three');
$array_2 = Array('red','blue','green');
Is there a dynamic way to create Setters and Getters for an array with single values?
Thus, the class will look something like this:
class xFromArray() {
}
So, if above, if I passed $ array_1, it would generate something like this:
private $one;
setOne($x) {
$one = $x;
}
getOne() {
return $one;
}
if I passed $ array_2, it will generate something like this:
private $red;
setRed($x) {
$red = $x;
}
getRed() {
return $red;
}
So would I call it anyway? (My best guess, but that doesn't seem to work)
$xFromArray = new xFromArray;
foreach($array_1 as $key=>$data) {
$xFromArray->create_function(set.ucfirst($data)($data));
echo $xFromArray->create_function(get.ucfirst($data));
}
source
share