doubai9014 2013-12-06 17:18
浏览 46

php方法意外t_string [重复]

This question already has an answer here:

I am working on a php method that giving me a syntax error on the third line of the method body. Commenting out the line does not do anything for me. Only by commenting out the entire method, does it actually go away. Am I missing something here?

public function get(Array $array) {
    if(array_key_exists('data', $array)) {
        if($array['data'] == '*') {
            $fieldString = '*';
        } else { 
            $fieldString = '';
            for($x=0; $x < count($array['data']); $x++) {
                if($x == count($array['data']) - 1 ) {
                    $fieldString .= $array['data'][$x].' ';
                } else {
                    $fieldString .= $array['data'][$x].', ';
                }
            }
        }
        if(array_key_exists('table', $array)) {
            $table = $array['table'];
        }
        if(array_key_exists('conditions', $array)) {
            $condition = $array['conditions'];
            $filter = '';
            foreach($condition['cond'] as $cond) {
                if(array_key_exists('type', $cond)) { 
                    $filter .= $cond['type'].' ';
                }
                if(array_key_exists('field', $cond)) {
                    $filter .= $cond['field']. ' = '; 
                }
                if(array_key_exists('value', $cond)) {
                    $filter .= $cond['value'];
                }
            }
        }

        $result = $mysqli->query("SELECT ".$fieldString." FROM ".$table. " ".$filter);
        $response = $result->fetch_assoc();
        if(!empty($response)) {
            return $response;
        } else {
            echo 'response array from get model is empty';
        }
    } else {
        echo '<h3>array data not set for _get() in model </h3>';
    }    
}
</div>
  • 写回答

2条回答 默认 最新

  • douyin8813 2013-12-06 17:24
    关注

    Is the method contained within the class. Sometimes I accidentally put a class function at the end of the class file but outside the ending }. If it is not a class method, remove 'public'.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集