Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Created November 12, 2013 10:35
Show Gist options
  • Save ihsanberahim/7428822 to your computer and use it in GitHub Desktop.
Save ihsanberahim/7428822 to your computer and use it in GitHub Desktop.
merge 2 array as column
<?php
$column1 = array(1,2,3,4);
$column2 = array('test','test','test','test');
$table = array();
//Example 1
/*foreach($column1 as $key => $row){
$table[] = array($column1[$key],$column2[$key]);
}*/
//or
//Example 2
$table = array_map(function($a,$b){
// return array($a,$b); //merge column as array
return "$a,$b"; //merge column as string
},$column1,$column2);
var_dump($table);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment