Last active
August 29, 2015 14:17
-
-
Save beeeku/6fb99a86d84c880a7433 to your computer and use it in GitHub Desktop.
Browntape Question no 3 Answer
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 | |
$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