Structs data type in php?

后端 未结 7 1433
悲哀的现实
悲哀的现实 2020-12-07 17:47

Can anyone give me example for structs data type in php ? How come there is something like structs in php all of a sudden ?

相关标签:
7条回答
  • 2020-12-07 18:14

    Closest you'd get to a struct is an object with all members public.

    class MyStruct {
        public $foo;
        public $bar;
    }
    
    $obj = new MyStruct();
    $obj->foo = 'Hello';
    $obj->bar = 'World';
    

    I'd say looking at the PHP Class Documentation would be worth it. If you need a one-off struct, use the StdObject as mentioned in alex's answer.

    0 讨论(0)
提交回复
热议问题