Alko
Alko

Reputation: 1439

Php, implode and join multiple values

I'm not sure how to process the following:

Here is my post array:

client[] 15
client[] 16
team[] 1,8
team[] 3,4,2
staff[] 5
staff[] 6

For the client and staff arrays, I use implode like:

function _implode($array) {
          $result = array();
          foreach ($array as $row) {
              if ($row != '') {
                  array_push($result, $row);
              }
          }
          return implode(",", $result);
}

$clients = _implode($_POST['client']);
$staff= _implode($_POST['staff']);

How I need to process team post which is already coma separated and combine all of the above into final result like so:

$final = "15,16,1,8,3,4,2,5,6";

Upvotes: 1

Views: 604

Answers (1)

leeor
leeor

Reputation: 17781

Just combine all the initial form arrays into one array with array_merge. Then you can implode that whole new array. Something like this:

$final_array = array_merge($_POST['client'], $_POST['staff'], $_POST['team'])
$final = implode(",", $final_array);

Upvotes: 1

Related Questions