I want to remove the whitespace between the arrays, but I've used different codes like trim but it does not remove. I think because trim is fro " " outside space and not between the words itself. I'm using PHP.
This is for R, but something like this: How to remove all whitespace from a string?
I've changed my code to this:
<?php
function combinations($arr, $n)
{
$res = array();
foreach ($arr[$n] as $item)
{
if ($n==count($arr)-1)
$res[]=$item;
else
{
$combs = combinations($arr,$n+1);
foreach ($combs as $comb)
{
$res[] = "$item $comb";
}
}
}
return $res;
}
$words = array(array(
'PY7AD022031',
'AD022031',
'CB5A09XQXU',
),array(
'HELLO',
'3040',
'3022031',
'07W11',
'4170B',
'0682',
'35570401',
'103448',
), array(
'HELLO',
'3040',
'3022031',
'07W11',
'4170B',
'0682',
'35570401',
'103448',
));
$combos = combinations($words,0);
$comma_separated = implode("<br />", $combos);
print("<pre>".print_r($comma_separated,true)."</pre>");
//var_dump($combos);
?>
It echo's
PY7AD022031 HELLO HELLO
PY7AD022031 HELLO 3040
PY7AD022031 HELLO 3022031
PY7AD022031 HELLO 07W11
PY7AD022031 HELLO 4170B
But I want
PY7AD022031HELLOHELLO
PY7AD022031HELLO3040
PY7AD022031HELLO3022031
PY7AD022031HELLO07W11
PY7AD022031HELLO4170B
", $combos); print(" ");` Prints it like `PY7AD022031 HELLO HELLO` `PY7AD022031 HELLO 3040` `PY7AD022031 HELLO 3022031` `PY7AD022031 HELLO 07W11` `PY7AD022031 HELLO 4170B` But how to remove the spacing between the words? – MOTIVECODEX Jun 23 '12 at 17:23
", $combos);` is better. Without `
` it will do the same as with `
` but everything is on one line. both ways will not remove the whitespace between ONE combination. That's what I want – MOTIVECODEX Jun 23 '12 at 17:53