Reputation: 237
I'm trying to get all the paths from all the rows and to add them (after exploding) to one array (in order to present them as checkbox)
This is my code:
$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);
}
}
My output is like that:
Array ( [0] =>
Array ( [0] => [1] => my [2] => path )
[1] => Array ( [0] => [1] => another [2] => one )
How can i combine them to one array?
I want to get something like this:
Array ( [0] => [1] => my [2] => path [3] => another [4] => one )
Thank you!
Upvotes: 6
Views: 12116
Reputation: 5499
Check out 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);
}
}
Upvotes: 0
Reputation: 6330
Take a look at the array_merge function:
http://php.net/manual/en/function.array-merge.php
Use the following lines of code:
$path = explode("/", $fpath);
$exp = array_merge($exp, $path);
HTH.
Upvotes: 10