在php中构造数据类型? [英] Structs data type in php?

查看:65
本文介绍了在php中构造数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我示例php中的structs数据类型?怎么突然在php中出现类似struct的东西?

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

推荐答案

最接近结构的对象是所有成员都是公共对象.

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';

我想看看 PHP类文档是值得的. 如果您需要一次性结构,请使用Alex答案中提到的StdObject .

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.

这篇关于在php中构造数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆