Compilate data from one mass to several
-
I don't understand the php of the generators, so I'm asking you to help There's a mass:
$arrayName = array( '0' => '1X', '1' => '1', '2' => '1', '3' => '1', '4' => '1', '5' => '1', '6' => '1', '7' => '1', '8' => '1', '9' => '1', '10' => '1', '11' => '1', '12' => '1', '13' => '1', '14' => '1', );
There are two variants of this range:
AND DEVELOPMENT
$arrayName = array( '0' => '1', '1' => '1', '2' => '1', '3' => '1', '4' => '1', '5' => '1', '6' => '1', '7' => '1', '8' => '1', '9' => '1', '10' => '1', '11' => '1', '12' => '1', '13' => '1', '14' => '1', );
AND TWO
$arrayName = array( '0' => 'X', '1' => '1', '2' => '1', '3' => '1', '4' => '1', '5' => '1', '6' => '1', '7' => '1', '8' => '1', '9' => '1', '10' => '1', '11' => '1', '12' => '1', '13' => '1', '14' => '1', );
It was easy. I mean, the key number 0 has to be broken into one symbol, so let's say str_split's function and generating all possible options. In this example, there's only two options, but there's this mass.
$arrayName = array( '0' => '1X', '1' => '1X2', '2' => '1X2', '3' => '1', '4' => '1', '5' => '1', '6' => '1', '7' => '1', '8' => '1', '9' => '1', '10' => '1', '11' => '1', '12' => '1', '13' => '1', '14' => '1X2', );
The options will be 54, and all of them need to begenerating in such a way as not to be the same.
The number of options in the mass is what I think.
$i = 1; foreach ($arrayName as $key => $value) { $count = str_split($value); $i = $i*count($count); } echo $i;
Tell me where to drop, maybe it's easier than it looks. ♪ ♪
Thank you!
-
We can do this:
<?php $arrayName = array( '0' => '1X', '1' => '1X2', '13' => '1', '14' => 'X2' );
function array_rec($array)
{
global $arrayout;
foreach ($array as $key => $value)
{
$count = strlen($value);
if ($count > 1)
{
for ($i = 0; $i < $count; $i++)
{
$array2 = $array;
$array2[$key] = $value[$i];
array_rec($array2);
}
return;
}
}
$arrayout[] = $array;
return;
}$arrayout = array();
array_rec($arrayName);
print_r($arrayout);
Result (measured so that there's not a big conclusion):
Array
(
[0] => Array
(
[0] => 1
[1] => 1
[13] => 1
[14] => X
)[1] => Array
(
[0] => 1
[1] => 1
[13] => 1
[14] => 2
)[2] => Array
(
[0] => 1
[1] => X
[13] => 1
[14] => X
)[3] => Array
(
[0] => 1
[1] => X
[13] => 1
[14] => 2
)[4] => Array
(
[0] => 1
[1] => 2
[13] => 1
[14] => X
)[5] => Array
(
[0] => 1
[1] => 2
[13] => 1
[14] => 2
)[6] => Array
(
[0] => X
[1] => 1
[13] => 1
[14] => X
)[7] => Array
(
[0] => X
[1] => 1
[13] => 1
[14] => 2
)[8] => Array
(
[0] => X
[1] => X
[13] => 1
[14] => X
)[9] => Array
(
[0] => X
[1] => X
[13] => 1
[14] => 2
)[10] => Array
(
[0] => X
[1] => 2
[13] => 1
[14] => X
)[11] => Array
(
[0] => X
[1] => 2
[13] => 1
[14] => 2
))