How do I get the value from object(stdClass)?

前端 未结 3 760
梦如初夏
梦如初夏 2020-12-09 07:18

Using PHP, I have to parse a string coming to my code in a format like this:

object(stdClass)(4) { 
    [\"Title\"]=> string(5) \"Fruit\" 
    [\"Color\"]         


        
3条回答
  •  臣服心动
    2020-12-09 08:13

    Example StdClass Object:

    $obj = new stdClass();
    
    $obj->foo = "bar";
    

    By Property (as other's have mentioned)

    echo $obj->foo; // -> "bar"
    

    By variable's value:

    $my_foo = 'foo';
    
    echo $obj->{$my_foo}; // -> "bar"
    

提交回复
热议问题