gpt4 book ai didi

php - 在 explode 函数后将值添加到一个数组

转载 作者:可可西里 更新时间:2023-10-31 22:07:25 25 4
gpt4 key购买 nike

我试图从所有行中获取所有路径并将它们(展开后)添加到一个数组中(以便将它们显示为复选框)

这是我的代码:

$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  )

谢谢!

最佳答案

看看 array_merge 函数:

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

使用以下代码行:

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

HTH.

关于php - 在 explode 函数后将值添加到一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4500370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com