在爆炸功能之后向一个阵列添加值

时间:2010-12-21 14:38:01

标签: php arrays

我正在尝试从所有行获取所有路径并将它们(在爆炸后)添加到一个数组(以便将它们显示为复选框)

这是我的代码:

$result = mysql_query("select path from audit where ind=$ind");
$exp = array();
while($row = mysql_fetch_array($result))
  {
    foreach ($row as $fpath)
      {
       $path = explode("/", $fpath);
       array_push($exp, $path);
      }
  }

我的输出是这样的:

Array ( [0] => 
   Array ( [0] => [1] => my [2] => path  ) 
   [1] => Array ( [0] => [1] => another [2] => one  )

如何将它们组合成一个阵列?

我想得到这样的东西:

Array ( [0] => [1] => my [2] => path  [3] => another [4] => one  )

谢谢!

2 个答案:

答案 0 :(得分:7)

看一下array_merge函数:

http://php.net/manual/en/function.array-merge.php

使用以下代码行:

$path = explode("/", $fpath);
$exp = array_merge($exp, $path);

HTH。

答案 1 :(得分:0)

结帐array functions

$result = mysql_query("select path from audit where ind=$ind");
$exp = array();
while($row = mysql_fetch_array($result))
  {
    foreach ($row as $fpath)
      {
       $path = explode("/", $fpath);
       $exp = array_merge($exp, $path);
      }
  }