php convert array of arrays to single array code example

Example 1: convert multidimensional array to single array php

$singleArray = []; 
foreach ($parentArray as $childArray) 
{ 
    foreach ($childArray as $value) 
    { 
    $singleArray[] = $value; 
    } 
}

Example 2: php multiple array to single array

$array = array_column($array, 'plan'); 
// plan adalah nama kolom nya  
// $array adalah variable nya 
// semisal pengen membuat get data jadi single array bisa seperti ini 
     $CI = get_instance(); 
	 $DB1 = $CI->load->database('nama_db', TRUE);
	 $sql = "select dept from v_dept_distinct order by dept asc ";
	  $query=$DB1->query($sql);
	  // print_r(array_column($query->result_array() , 'dept')); 
	  return  array_column($query->result_array() , 'dept');

Tags:

Php Example