Here is what I am trying to accomplish:
function foo($args) { switch($args['type']) { case 'bar': bar($args['data']);
This is basically a way to use named parameters in PHP.
Now, to build this $args array, I have to write ugly syntax, for example:
$builtArgs = array('type' => 'bar', 'data' => array(1, 2, 3), 'data2' => array(5, 10, 20) ); foo($builtArgs);
Which gets uglier when I add more dimensions to the array, and also makes me write tons of array(...) constructs. Is there a nicer way to do this?
On the one hand, this could be done if we could use syntax like Python:
$buildArgs = {'type' : 'bar', 'data' : [1, 2, 3], 'data2' : [5, 10, 20]};
But this is PHP.
syntax coding-style php
quantumSoup
source share