Does PHP feature short hand syntax for objects?

前端 未结 7 622
囚心锁ツ
囚心锁ツ 2020-12-06 04:04

In javascript you can easily create objects and Arrays like so:

var aObject = { foo:\'bla\', bar:2 };
var anArray = [\'foo\', \'bar\', 2];

相关标签:
7条回答
  • 2020-12-06 04:45

    Like the json_decode idea, wrote this:

    function a($json) {
     return json_decode($json, true); //turn true to false to use objets instead of associative arrays
    }
    
    //EXAMPLE
    $cat = 'meow';
    
    $array = a('{"value1":"Tester", 
      "value2":"'.$cat.'", 
      "value3":{"valueX":"Hi"}}');
    
    print_r($array);
    
    0 讨论(0)
提交回复
热议问题