Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add values to one array after explode function

Tags:

arrays

php

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!

like image 657
Ronny Avatar asked Dec 21 '10 14:12

Ronny


People also ask

What does the explode () function return?

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.

What does explode () do in PHP?

The explode() function breaks a string into an array. Note: The "separator" parameter cannot be an empty string. Note: This function is binary-safe.

How to explode array in SQL?

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.


1 Answers

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.

like image 163
RabidFire Avatar answered Sep 26 '22 01:09

RabidFire