-5

Below function i.e getBooksInsertedCount code gives output like this

  array(3) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
  [2]=>
  string(1) "1"
}

getBooksInsertedCount

function getBooksInsertedCount()
{  
  $this->load->database();    
  $query = "SELECT count(book_id) as count,date(created_date) as cdate FROM `bookdetails` WHERE  (created_date BETWEEN '2018-06-25' AND '2018-06-28') GROUP by created_date order by created_date asc";
  $result = $this->db->query($query);
 $ret = array();

   foreach ($result->result_array() as $row ) {
            $ret[] = $row['count'];
   } 
     return $ret;
  }

Expected output(Note here: [0]=> string(1) is removed)

array(1, 2, 1);
Dan
  • 2,086
  • 11
  • 71
  • 137

2 Answers2

1

Your expected output matches the current output, apart from the type (string VS int)

If I understand your question correctly, you'd like to remove the array indexes.

When creating an array like this array('first', 'second'), every value is assigned an index based on it's position, it's not possible to remove this (would also make it very hard to select something you need from it).

So the above example actually matches array(0 => 'first', 1 => 'second').

Bert H
  • 1,087
  • 1
  • 15
  • 29
0

You can use cast the value (type juggling).

Change,

$ret[] = $row['count'];

To,

$ret[] = (int) $row['count'];
Script47
  • 14,230
  • 4
  • 45
  • 66