6

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!

Ronny
  • 227
  • 2
  • 5
  • 10

2 Answers2

10

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.

RabidFire
  • 6,280
  • 1
  • 28
  • 24
0

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);
      }
  }
Fabio Mora
  • 5,339
  • 2
  • 20
  • 30