Php array_values不起作用

时间:2011-04-17 12:15:05

标签: 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');
        $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 
            )

    )  

我该怎么办?

1 个答案:

答案 0 :(得分:7)

就是这一行:

$allDirections[] = array();

您正在将第一个项目设置为空白数组。我想你可能要做的就是将变量定义为数组。可能只是一个错字。

尝试:

 $allDirections = array();

另外,这不是警告吗?也许您应该提交错误报告。