Here's what I am trying to accomplish:
function foo($args) {
switch($args['type']) {
case 'bar':
bar($args['data']); // do something
break;
}
}
// or something like that
Which is basically a way of using named parameters in PHP.
Now, in order to build this $args
array, I am forced to write ugly syntax like:
$builtArgs = array('type' => 'bar',
'data' => array(1, 2, 3),
'data2' => array(5, 10, 20)
);
foo($builtArgs);
Which gets uglier as I add more dimensions to the array, and also forces me to write tons of array(...)
constructs. Is there a prettier way to do this?
For one thing, it could be done if we could use Python-like syntax:
$buildArgs = {'type' : 'bar', 'data' : [1, 2, 3], 'data2' : [5, 10, 20]};
But it is PHP.