Reputation: 157
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?
Upvotes: 1
Views: 1347
Reputation: 532
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.
Upvotes: 7