我想刪除數組之間的空白,但我使用了不同的代碼,如trim,但它不會刪除。我認爲是因爲修剪在外面空間而不是在詞語本身之間。我使用PHP。如何從字符串中的字符串中刪除空格PHP
這是R,但這樣的事情:How to remove all whitespace from a string?
我已經改變了我的代碼如下:
<?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);
?>
它呼應的
PY7AD022031 HELLO HELLO
PY7AD022031 HELLO 3040
PY7AD022031 HELLO 3022031
PY7AD022031 HELLO 07W11
PY7AD022031 HELLO 4170B
但我想
PY7AD022031HELLOHELLO
PY7AD022031HELLO3040
PY7AD022031HELLO3022031
PY7AD022031HELLO07W11
PY7AD022031HELLO4170B
嘗試[破滅](http://php.net/implode) – hjpotter92
[str_replace函數(http://www.php.net/str_replace)與環豬頭...或者只是編輯組合()函數 – goat
@rambocoder我已經添加了組合函數,任何想法改變什麼? – MOTIVECODEX