7

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!

1
  • what you expect to have in final ? Commented Dec 21, 2010 at 14:39

2 Answers 2

11

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.

Sign up to request clarification or add additional context in comments.

Comments

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);
      }
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.