php 中如何定义这样一个对象在js中可以这样定义这样一个对象<script type="text/javascript">
var my_obj={
"forder":"tem",
"page":"index.htm",
"class":["w250","h260", "pdl20"]
}
</script>请问在php中这个对象应该怎么定义法?

解决方案 »

  1.   


    $my_obj = array(
      'forder'=>'tem',
      'page'=>'index.htm',
      'class'=>array(
        'w250',
        'h260',
        'pd120',
      ),
    );
      

  2.   


    $s='{"forder":"tem",
    "page":"index.htm",
    "class":["w250","h260", "pdl20"]
    }';
    print_r(json_decode($s,true));
    echo json_encode(json_decode($s,true));
      

  3.   

    php 原来array就是object ,谢谢
      

  4.   


    也未必完全是... 不过使用 array 来完成 object 的东西 , 对于数据来讲是OK的.如果你的 object 有方法, 那就需要使用 class 来完成.