I am asking your preference between two similar solutions.
First way :
public function test($myvar) {
switch ($myvar) {
case 'test1': return [
'value' => 'Value of test1',
'short' => 'Val 1'
];
break;
}
}
$this->test('test1')['short'] // Val 1
Second way:
public function test($myvar, $key) {
switch ($myvar) {
case 'test1': $array = [
'value' => 'Value of test1',
'short' => 'Val 1'
];
}
return $array[$key];
}
$this->test('test1', 'short') // Val 1
Even if both function return same value, what is the most elegant and readable way for you guys ?