PHP foreach对象错误

时间:2017-11-14 14:23:50

标签: php foreach

我后来使用POST方法我想将POST请求添加到变量但是我收到错误。为什么我会遇到对象错误?

错误代码

  

PHP Catchable致命错误:类stdClass的对象无法转换为字符串

发布数据

array(16) { ["lat"]=> string(15) "41.008550564147" ["lng"]=> string(15) "28.978239484058" ["time"]=> string(1) "6" ["type"]=> string(6) "status" ["status"]=> string(0) "" ["category"]=> string(0) "" ["subCategory"]=> string(0) "" ["room"]=> string(0) "" ["buildingAge"]=> string(0) "" ["sfloor"]=> string(0) "" ["floor"]=> string(0) "" ["square"]=> string(0) "" ["price"]=> string(0) "" ["currency"]=> string(0) "" ["value"]=> string(0) "" ["feedback"]=> string(0) "" }

PHP代码

    foreach ($_POST as $key => $value) {
        $params .= $key . "=" . $value . "&";
    }
    echo $params;

1 个答案:

答案 0 :(得分:1)

改为使用http_build_query

echo http_build_query($_POST);