Arrays Zend返回为数组
我想从表中选择一个特定的列,并以简单数组的形式返回结果。我有以下代码Arrays Zend返回为数组,arrays,zend-framework,Arrays,Zend Framework,我想从表中选择一个特定的列,并以简单数组的形式返回结果。我有以下代码 $select = $this->select(); $select = $select->from($this,array('DISTINCT(conversation_id)','conversation_id')) ->where('user_id =?',$user_id); return $this->fetchAll($select)->toArray
$select = $this->select();
$select = $select->from($this,array('DISTINCT(conversation_id)','conversation_id'))
->where('user_id =?',$user_id);
return $this->fetchAll($select)->toArray();
问题是,返回的结果是2D。因此,如果我想得到结果,我必须像$result[0]['conversation\u id']
那样。我怎样才能得到它,只需键入$result[I]
谢谢您需要使用以下代码行
return $this->fetchRow($select)->toArray();
这就是你要找的吗?
return$this->fetchAll($select)->current()->toArray()
也可以。为什么要使用数组,为什么不直接使用对象:$result->conversation\u id
,这只是一个想法。是的,我想没有这个可能有办法做到这一点?
$select = $this->select();
$select = $select->from($this,array('DISTINCT(conversation_id)'))
->where('user_id =?',$user_id);
$fetchedData = $this->fetchAll($select);
$dataArray = array();
foreach($fetchedData as $data)
{
$dataArray[] = $data->conversation_id;
}
return $dataArray;