Skip to content

Instantly share code, notes, and snippets.

@beeeku
Last active August 29, 2015 14:17
Show Gist options
  • Save beeeku/6fb99a86d84c880a7433 to your computer and use it in GitHub Desktop.
Save beeeku/6fb99a86d84c880a7433 to your computer and use it in GitHub Desktop.
Browntape Question no 3 Answer
<?php
$result = array();
function getSku($key, $params)
{
$rv = array();
$i = count($params);
while (0 < $i--) {
array_unshift($rv, $params[$i][$key % count($params[$i])]);
$key = (int) ($key / count($params[$i]));
}
return $rv;
}
function generateSku($product_name, $arr)
{
$len = 1;
foreach ($arr as $item) {
$len = $len * count($item);
}
for ($i = 0; $i < $len; $i++) {
$a = getSku($i, $arr);
$result[]="". $product_name . "-" . join(' ', $a);
}
return $result;
}
$new = array(
'color' => array( 'black','white'),
'size' => array( '16gb','32gb','64gb')
);
$array1 = array_values($new);
$result = generateSku("Iphone 4s", $array1);
print_r($result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment