這是我的代碼,目前無法正常工作。我怎樣才能使它工作?我的願望是使輸出像一個字符串(當然我知道如何「轉換」數組是string):帶有一個輸出的多陣列
話改變,添加和刪除,使之
代碼:
<?php
header('Content-Type: text/html; charset=utf-8');
$text = explode(" ", strip_tags("words altered added and removed to make it"));
$stack = array();
$words = array("altered", "added", "something");
foreach($words as $keywords){
$check = array_search($keywords, $text);
if($check>(-1)){
$replace = " ".$text[$check].",";
$result = str_replace($text[$check], $replace, $text);
array_push($stack, $result);
}
}
print_r($stack);
?>
輸出:
Array
(
[0] => Array
(
[0] => words
[1] => altered,
[2] => added
[3] => and
[4] => removed
[5] => to
[6] => make
[7] => it
)
[1] => Array
(
[0] => words
[1] => altered
[2] => added,
[3] => and
[4] => removed
[5] => to
[6] => make
[7] => it
)
)
您的期望輸出究竟是什麼?你的問題很不清楚。 – Milanzor
你可以使用implode('',$ stack [0]); –
implode僅輸出第一個數組結果 – Nick