Jump to content

Getting new array of values from array


mrscoop

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/285945-getting-new-array-of-values-from-array/
Share on other sites

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));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.