1

I have a method in Zend framework

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;
    }

If I call this method it returns

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 
        )

) 

I need this method must return

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 
            )

    )  

What can I do?

1 Answer 1

7

It's this line:

$allDirections[] = array();

You are setting the first item to a blank array. I think maybe what you are looking to do is just define the variable as an array. Could simply be a typo.

Try:

 $allDirections = array();

Also, doesn't this throw a warning? Perhaps you should up your error reporting.

Sign up to request clarification or add additional context in comments.

2 Comments

+1, This is why you should always learn the php fundamentals before a framework
Perhaps you should mark this as answered then? Not sure what protocol is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.