当前位置: 动力学知识库 > 问答 > 编程问答 >

mongodb - how to echo object or hash type field php

问题描述:

Please how do I echo or obtain the values of a field of type object?

I first encoded, replaced string and decoded the code as below:

$mongorow = json_encode($mongorow);

$mongorow= preg_replace("/_DOT_/", ".", $mongorow);

$mongorow = json_decode($mongorow);

And then in my form I'm trying to use the fields as below:

value="<?php echo $mongorow->name;?>" //this works producing value of name

value="<?php echo $mongorow->properties;?>" //this produces an error where properties is of type object

Error message I get is (symfony)

Catchable Fatal Error: Object of class stdClass could not be converted to string in ...

网友答案:

First try to debug the type of the $mongorow->properties you can debug the object by using the var_dumb function.

Try this:

var_dump($mongorow);

And you will get the exact data.

For more read here about the var_dump.

网友答案:

You can use var_dump() or print_r() function to display the object or hashtype field

 echo "<pre>"; var_dump($mongorow); 

 print_r($mongorow);
网友答案:

If you want to assign object to the variable as a string use:

serialize($obj);

If you want to just dump value on screen use:

var_dump($obj);`
分享给朋友:
您可能感兴趣的文章:
随机阅读: