这是我的代码,目前无法正常工作。我怎样才能使它工作?我的愿望是使输出像一个字符串(当然我知道如何“转换”数组是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