限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。

PHP基础

php获取 request payload中的数据

if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) { $userinfo1 = $GLOBALS['HTTP_RAW_POST_DATA']; } else { $userinfo1 = file_get_contents('php://input'); } $userinfo = object_to_array(json

作者
王明昌
发布时间
       if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
            $userinfo1 = $GLOBALS['HTTP_RAW_POST_DATA'];
        } else {
            $userinfo1 = file_get_contents('php://input');
        }
        $userinfo = object_to_array(json_decode($userinfo1));//z转化为数组

/**
 * 对象 转 数组
 *
 * @param object $obj 对象
 * @return array
 */
function object_to_array($obj) {
    $obj = (array)$obj;
    foreach ($obj as $k => $v) {
        if (gettype($v) == 'resource') {
            return;
        }
        if (gettype($v) == 'object' || gettype($v) == 'array') {
            $obj[$k] = (array)object_to_array($v);
        }
    }
 
    return $obj;
}

php获取 request payload中的数据
0/500
友善分享您的看法。
反馈邮箱