0

I have a result array that comes back from CodeIgniter looking like this:

Array
(
    [ILS] => ils
    [0] => Array
        (
            [laser_id] => 1
            [sort_order] => 1
            [laser_name] => ILS12.75
            [laser] => ils1275
            [image] => ils1275
            [link] => ils1275

        )
    [1] => Array
        ( .. )
    etc.

}

I used array_merge to get the ILS item into the array, but I need it to get it into the array[0]. I also need to get a similar item into array[1] and so on in the result array. How do I do this? Here is how I got the ILS item in:

function get_laser_configs() 
{   
   $this->db->order_by('sort_order');
   $query = $this->db->get('all_lasers')->result_array();

  $ils = array('ILS' => 'ils');
  return array_merge($ils, $query);
}
sehummel
  • 5,476
  • 24
  • 90
  • 137

1 Answers1

0

No need for array_merge, simply do:

$query[0]['ILS'] = 'ils';

If you want to do it for each element in the array:

foreach ($query as $key => $q) {
    $query[$key]['ILS'] = 'ils';
}
netcoder
  • 66,435
  • 19
  • 125
  • 142