php - Convert an array of simple arrays into an array of Associative arrays? -
i'm using php , i'm using array listed here: https://gist.github.com/aghouseh/3926213
so it's array state name, , within state names list of counties, this:
$counties = array( "alabama" => array( "autauga county", "baldwin county", "barbour county", "bibb county") "california => array( "los angeles county", "san francisco county")); so i'm trying accomplish this:
$counties = array( "alabama" => array( "autauga county" => "autauga county", "baldwin county" => "baldwin county", "barbour county" => "barbour county", "bibb county" => "bibb county") "california => array( "los angeles county" => "los angeles county", "san francisco county" => "san francisco county")); i wanna make second level array associative array. tried search answer , came didn't work:
foreach ($counties $state) { foreach ($state $county) { array_combine($county, $county); } }
create new array wish , replace original it:
foreach ($counties $state => $x) { $c = array(); foreach ($x $county) { $c[$county] = $county; } $counties[$state] = $c; }
Comments
Post a Comment