开发者

in a document of MongoDB, i have a key/value such that value is an association array (inserted using php); how can iterate

in a docum开发者_如何学Goent of MongoDB, i have a key/value such that value is an association array (inserted using php); how can iterate throuth this array

array(4) {
  ["_id"]=>
  object(MongoId)#8 (0) {
  }
  ["tabid"]=>
  string(6) "123456"
  ["type"]=>
  string(6) "design"
  ["data"]=>
  array(2) {
    ["article"]=>
    string(57) "Bla bla"
    ["comts"]=>
    string(57) "Bla2 bla2"
  }
}

i did i var_dump to get this.

here is how what i did, but its not working

 foreach($arr['data'] as $k => $v){

    $txt+=sprintf("%s<br><i>%s</i><br><br>",$k,(string)$v); }

any help please?


why $txt+ ? + is operator for addition in PHP. $txt will be equal to a number in the end.

For concatenation two strings use .

foreach($arr['data'] as $k => $v){
    $txt .= sprintf("%s<br><i>%s</i><br><br>",$k,(string)$v); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜