I need to create a sql sentence from a dinamic structure. The structure come from a multidimensional array. It is more difficult explain that show it, so I show 3 examples:
Example1: If I have this array:
myarry Array
(
[5] => Array
(
[0] => 2
[1] => 5
)
[6] => Array
(
[0] => 11
)
)
I need to create a string like: (2 AND 11) OR (5 AND 11)
Example2: If I have this array:
myarry Array
(
[5] => Array
(
[0] => 2
[1] => 5
)
[6] => Array
(
[0] => 11
[1] => 8
)
)
I need to create a string like: (2 AND 11) OR (5 AND 11) OR (2 AND 8) OR (5 AND 8)
Example3: If I have this array:
myarry Array
(
[5] => Array
(
[0] => 2
[1] => 5
)
[6] => Array
(
[0] => 11
)
[7] => Array
(
[0] => 70
[1] => 71
[2] => 72
)
)
I need to create a string like: (2 AND 11 AND 70) OR (2 AND 11 AND 71) OR (2 AND 11 AND 72) OR (5 AND 11 AND 70) OR (5 AND 11 AND 71) OR (5 AND 11 AND 72)
And so on... The index on the array are not important.
I have tried already:
foreach ($myarry as $clave => $feature){
${"feat_$n"} = $feature;
$n++;
}
$quan= count($myarry);
foreach ($feat_0 as $feature1) {
for ($m = 1; $m < $quan; $m++){
$name = "feat_{$m}";
foreach ($$name as $feature2) {
echo "OR feature1: ".$feature1." AND feature2: ".$feature2."<br>";
}
}
}
And also:
foreach ($myarry as $clave => $feature){
${"feat_$n"} = $feature;
$n++;
}
$i = 0;
foreach ($feat_0 as $clave0 => $feature0) {
for ($m = 1; $m < $cantidad; $m++){
$name = "feat_{$m}";
foreach ($$name as $clave1 => $feature1) {
echo "-feature0: ".$feature0." - feature1: ".$feature1." - i: ".$i." - m: ".$m."<br>";
$i++;
if($m == 1)
$indice = $feature1;
else
$pena[$feature0][$indice][$i] = $feature1;
}
$i=0;
}
}
But I'm not even close to the solution :( I hope the question is clear. Any help will be welcome!