Php数组_值不起作用

Php数组_值不起作用,php,zend-framework,Php,Zend Framework,我在Zend框架中有一个方法 public static function selectWithWhere(array $row_names, array $values) { $db = Zend_Db_Table_Abstract::getDefaultAdapter(); $selectData = new Zend_Db_Select($db); $selectData->from('other_directions');

我在Zend框架中有一个方法

public static function selectWithWhere(array $row_names, array $values) {
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();

        $selectData = new Zend_Db_Select($db);
        $selectData->from('other_directions');
        $i = 0;
        $length = count($values);
        $where = array();
        foreach($row_names as $row_name){
            $where[] = $selectData->where($row_name . '=?', $values[$i]);
            $i++;
        }
        $where[$length - 1];
        $data = $db->query($selectData);
        $data = $data->fetchAll();
        $allDirections[] = array();
        if($data == null){
            return null;
        }
            foreach ($data as $d) {
                $direction = new Admin_Object_OtherDirections();
                $direction->setOtherDirectionId($d['other_direction_id']);
                $direction->setNoticeId($d['notice_id']);
                $direction->setDirectionTypeId($d['direction_type_id']);
                $direction->setOtherDirectionName($d['other_direction_name']);
                if(isset($direction)){
                    $allDirections[] = $direction;
                }
            }
            $allDirections = array_values($allDirections);
        return $allDirections;
    }
如果调用此方法,它将返回

Array
(
    [0] => Array
        (
        )

    [1] => Admin_Object_OtherDirections Object
        (
            [other_direction_id:private] => 1
            [notice_id:private] => 1
            [direction_type_id:private] => 4
            [other_direction_name:private] => Skver,Bunyodkor,Chorsu 
        )

) 
我需要这个方法必须返回

Array
    (
        [0] => Admin_Object_OtherDirections Object
            (
                [other_direction_id:private] => 1
                [notice_id:private] => 1
                [direction_type_id:private] => 4
                [other_direction_name:private] => Skver,Bunyodkor,Chorsu 
            )

    )  
我能做什么

就是这一行:

$allDirections[] = array();
您正在将第一项设置为空白数组。我想也许你要做的就是把变量定义为数组。可能只是打字错误

尝试:

还有,这不是一个警告吗?也许您应该增加错误报告。

这是一行:

$allDirections[] = array();
您正在将第一项设置为空白数组。我想也许你要做的就是把变量定义为数组。可能只是打字错误

尝试:


还有,这不是一个警告吗?也许你应该增加你的错误报告。

+1,这就是为什么你应该在框架之前学习php基础知识的原因也许你应该把它标记为已回答?不确定协议是什么。+1,这就是为什么在框架设计之前,您应该始终学习php基础知识的原因也许您应该将其标记为已回答?不确定协议是什么。