是因为数组$ result没有返回结果

时间:2016-12-09 20:01:35

标签: php

我收到错误无法使用stdClass类型的对象作为行上的数组

$rows['id'] = $result['id'];

是否因为数组$ result没有返回结果?

if ($tag == 'chins') {

        $clubId = $obj->club_id;
        if(isset($clubId))
        {
            $results = $db->club_chins($clubId);
        }else{
            $results = $db->chins();
        }

        if ($results != false) {
            // user found
            // echo json with success = 1

            $response["success"] = 1;
            $array = array();
            foreach($results as $result){
                $rows['id'] = $result['id'];

1 个答案:

答案 0 :(得分:2)

$result 不是数组,它是一个对象(在PHP中称为stdClass)。您需要使用->来获取属性。

$rows['id'] = $result->id;
相关问题