It’s the same thing!
Posted under Web Development articles on April 29th, 2010After spending an hour to come up with this:
function mapName($th_name, $th_order)
{
return(array($th_name => $th_order));
}
$order = array_map("mapName", $_POST['thFilename'], $_POST['raw_orders']);
$order_collapsed = array();
foreach ($order as $k => $v) {
foreach ($v as $k2 => $v2) {
$order_collapsed[$k2] = $v2;
}
}
… I found out that I can achieve the same goal by doing this:
$order_collapsed = array_combine($_POST['thFilename'], $_POST['raw_orders']);
To make a lemonade out of lemons, I did learn quite a bit about Array handling in PHP.
Got to hand it to the PHP community,due to their maturity (I’m using PHP 5, not even the latest 6), they have quite a collection of some nifty stuff that you often need to do with arrays. It’s just a matter of knowing what’s in the API before reinventing the wheel.