Last active
January 2, 2016 09:49
-
-
Save alancoleman/8285500 to your computer and use it in GitHub Desktop.
Build a multidimensional associative array from an array. Simple, but caught me out for a moment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Declare new array | |
$fieldsarrsql = array(); | |
// Loop through origional array | |
foreach ($origarray as $fieldsarr) { | |
// Populate new array with associated data | |
$fieldsarrsql[] = array( | |
'tablealias'=>$fieldsarr['tablealias'], | |
'columnname'=>$fieldsarr['columnname'], | |
'columnalias'=>$fieldsarr['fieldname'] | |
); | |
} | |
var_dump($fieldsarrsql); | |
?> | |
array | |
0 => | |
array | |
'tablealias' => string 'u' (length=1) | |
'columnname' => string 'first_name' (length=10) | |
'columnalias' => string 'first_name' (length=10) | |
1 => | |
array | |
'tablealias' => string 'u' (length=1) | |
'columnname' => string 'last_name' (length=9) | |
'columnalias' => string 'last_name' (length=9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment