public static function array_pack ($array, & $vs = null)
{
$in = $vs === null;
$as = null;
foreach ($array as $k => $v)
{
if (!isset($vs[$k]))
$vs[$k] = count($vs);
if (is_array($v))
{
$as[] = $vs[$k];
$as[] = self::array_pack($v, $vs);
}
else
{
if (!isset($vs[$v]))
$vs[$v] = count($vs);
$as[] = $vs[$k];
$as[] = $vs[$v];
}
}
return $in ? array($as, array_flip($vs)) : $as;
}
Code language: PHP (php)
array_pack
przez
Leave a Reply