Here is what I have:
public function get_model_by_make($make = null){
$model_data = $this->vehicle_model->get_model($make);
echo json_encode($model_data);
}
public function get_model($make){
$this->db->select('models_id, models_name');
$this->db->where('makes_id', $make);
$models_data = $this->db->get('Models');
$rows = array();
$rows[0] = '-Select-';
foreach($models_data->result() as $value){
$rows[$value->models_id] = $value->models_name;
}
return $rows;
}
The problem I'm having is if I pass a 0 or 1 to the get_model_by_make() function the json data that is returned without the array key.
Example:
$data = get_model_by_make(1)
echo $data;
Result:
["-Select-","CL","CSX","EL","Integra","Legend","MDX","NSX","RDX","RL","RSX",
"SLX","TL","TSX","Vigor"]
If the number passed is greater than 1 then its returned like this:
$data = get_model_by_make(2)
echo $data;
Result:
{"0":"-Select-","35":"Alliance","36":"Ambassador","37":"AMX","38":"Classic"}
Why is json_encode not returning the key/value pair for 0 or 1? If I var_dump the data the key/value is there.