PHP object like array

后端 未结 9 556
臣服心动
臣服心动 2020-12-10 00:53

I need to be able to set my object like this:

$obj->foo = \'bar\';

then I need to use it as an array like that:

if($obj[\'f         


        
9条回答
  •  暖寄归人
    2020-12-10 01:50

    You could also cast the object as an array:

    if((array)$obj['foo'] == 'bar'){
      //more code here
    }
    

提交回复
热议问题