mrscoop Posted February 4, 2014 Share Posted February 4, 2014 Beginner here. Not sure why but I arrays are a huge source of frustration for me. I have this query: $query = $this->_db->getQuery ( true ); $query->select( 'a.table,a.places'); $query->from ( '#__tbb_reserves as a '); $query->where ( 'id = ' . $tid ); $this->_db->setQuery ( $query ); $myarray =$this->_db->loadRowList(); resulting in this array array { [0]=array { [0]= "9" [1]="10" } [1]= array { [0]= "5" [1]= "10" } [2]= array { [0]= "4" [1]= "6" }} From which I would like to create 2 new arrays: one from key [0] $array1 = array(9,5,4) and one from key [1] $array2 = array(10,10,6) Any help on how I would go about this is appreciated. Please let me know if I have left anything important out in my question. Also, if anyone knows of a good tutorial on the subject I would be very grateful. Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted February 4, 2014 Solution Share Posted February 4, 2014 (edited) Use a foreach loop, to loop over the arrays in $myarray. Add each item in that array to separate arrays $myarray =$this->_db->loadRowList(); $tables = array(); $places = array(); foreach($myarray as $array) { $tables[] = $array[0]; $places[] = $array[1]; } printf('<pre>Tables %s</pre>', print_r($tables, true)); printf('<pre>Places %s</pre>', print_r($places, true)); Edited February 4, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
mrscoop Posted February 4, 2014 Author Share Posted February 4, 2014 Yes! Thank you! I appreciate the fast, straightforward & non-judgemental response! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.