1

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";
Alko
  • 1,421
  • 5
  • 25
  • 51

1 Answers1

1

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);
leeor
  • 17,041
  • 6
  • 34
  • 60