php - Array elements not showing? -


i trying print [0] element of array. code below creates array output says 'array'

$this->db->select('company_name'); $query = $this->db->get('companies'); $query = $query->result_array(); echo $query['company_name']; 

what trying echo array itself. if try echo array, php not show contents.

when results database, typically 2 dimensional array, is, array data more arrays. if echo data in top-most array's index 1, trying echo array, since located in first array.

in order contents, need use 2 indexes; 1 index of array, , 1 index of data in array:

<?php     $my_array = array(array(8, 2, 4), array(7, 12, 32), array(62, 2, 1));     echo $my_array[1][1] // echos 12     echo $my_array[1] // echos "array" because data @ index 1 array ?> 

or maybe want see contents of array. if so, print_r() function friend. recursive , lets see contents of arrays inside of arrays:

<?php     $my_array = array(array(8, 2, 4), array(7, 12, 32), array(62, 2, 1));     print_r($my_array);     /*         above output following:         array         (             [0] => array                 (                      [0] => 8                      [1] => 2                      [2] => 4                 )              [1] => array                 (                      [0] => 7                      [1] => 12                      [2] => 32                 )              [2] => array                 (                      [0] => 62                      [1] => 2                      [2] => 1                 )         )     */ ?> 

check out reference @ print_r() php reference more information.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -