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!
explode() is a built in function in PHP used to split a string in different strings. The explode() function splits a string based on a string delimiter, i.e. it splits the string wherever the delimiter character occurs. This functions returns an array containing the strings formed by splitting the original string.
The explode() function breaks a string into an array. Note: The "separator" parameter cannot be an empty string. Note: This function is binary-safe.
If EXPLODE is applied on an instance of SQL. ARRAY <T>, the resulting rowset contains a single column of type T where each item in the array is placed into its own row. If the array value was empty or null, then the resulting rowset is empty. If EXPLODE is applied on an instance of SQL.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With