Dear all.
I have faced with necessity to get the data from result array by certain column without using associative array.
For example, I want to get first column (id) from table which contains 10 rows with several columns.
If I use the clause $this->db->select('id'), I will get the result array, which contains 10 internal arrays filled column named 'id'.
I just want the function that returns me the non-associative array filled with data by field I signed for the situation I've described above.
I have already written the function I want. It's here:
PHP Code:
public function row_array_by_field($field = "")
{
$result = $this->result_array();
if(count($result) === 0)
{
return array();
}
$formatted_result = array();
$fields = array_keys($result[0]);
if(empty($field))
{
$field = $fields[0];
}
else
{
if(!in_array($field, $fields))
{
return array();
}
}
foreach($result as $row_result)
{
array_push($formatted_result, $row_result[$field]);
}
return $formatted_result;
}
I want the developers to put the function in the official CodeIgniter distribution, because some situations requires to get data in that way.