PHP: less ugly syntax for named parameters / arrays?

前端 未结 4 1354
暖寄归人
暖寄归人 2021-01-14 13:48

Here\'s what I am trying to accomplish:

function foo($args) {
 switch($args[\'type\']) {
  case \'bar\':
  bar($args[\'data\']);   // do something
  break;
          


        
4条回答
  •  清酒与你
    2021-01-14 14:47

    No, there is no "short-syntax" to write arrays nor objects, in PHP : you have to write all those array().
    (At least, there is no such syntax... yet ; might come in a future version of PHP ; who knows ^^ )

    But note that have too many imbricated arrays like that will makes things harder for people who will have to call your functions : using real-parameters means auto-completion and type-hinting in the IDE...

提交回复
热议问题