如何将其分解为变量数组?

时间:2010-12-17 19:18:17

标签: php arrays

我已经有了以下内容来爆炸$ tmp中的br ..

  $tmp = explode('<br>', $tmp);
  echo $tmp[0];
  echo "<br>";
  echo $tmp[1];

现在,在$ tmp [0]中有一堆文本,由管道“|”分隔。即:word1 | word2 | word3 | word4 | word5 注意,最后一次不会在管道中结束..

如何爆炸$ tmp [0]来抓取每一段文本,将它们变成一个数组,即:$ pipetxt [0],$ pipetxt [1]等,没有管道..

在上述情况发生后,我可以做与上述完全相同的事情吗?但是去吧;

$pipetxt = explode('|', $tmp[0]);
echo $pipetxt[0];
echo "<br>";
echo $pipetxt[1];

谢谢!

2 个答案:

答案 0 :(得分:1)

您的爆炸看起来不错,您可以使用foreach()输出所有$pipetxt

foreach($pipetxt as $out)
  echo $out . "<br>";

答案 1 :(得分:0)

但你应该采用一些循环。

$tmp = explode('<br>', $tmp);

foreach($tmp as $pipeline){
 $pipetxt_array = explode('|', $pipeline);
 foreach ($pipetxt_array as $output){
  echo $output."<br />";
 }
}
相关问题