merge arrays to one string
Hello,
I have a few repeating regions with checkbox values that I would like to append as one comma separated string.
Individual groups can be posted using the implode function from checkbox arrays []
But trying to merge these to one string is posing a problem.
Here is my code:
$a1 = ((isset($_POST["1pcCB"]))?implode(", ", $_POST["1pcCB"]):""));
$a2 = ((isset($_POST["desksetCB"]))?implode(", ", $_POST["desksetCB"]):"");
$a3 = ((isset($_POST["trimlineCB"]))?implode(", ", $_POST["trimlineCB"]):"");
$a4 = ((isset($_POST["bedRailCB"]))?implode(", ", $_POST["bedRailCB"]):"");
$a5 = ((isset($_POST["specialtyCB"]))?implode(", ", $_POST["specialtyCB"]):"");
$requestedPhones = array_merge($a1, $a2, $a3, $a4, $a5);
Is this not an array: ((isset($_POST["1pcCB"]))?implode(", ", $_POST["1pcCB"]):"")) ?
I'm looking to post $requestedPhones as the final string to be inserted. The individual elements seem to work, such as ((isset($_POST["1pcCB"]))?implode(", ", $_POST["1pcCB"]):"")) properly inserts a comma separated string to the target DB field.
And the array_merge() function works in testing if I use a test array such as :
$my_array1 = array ( 'a', 'b', 'c' );
$my_array2 = array ( 'd', 'e', 'f' );
// append one array to the other
$my_array = array_merge($my_array1, $my_array2);
// print the resulting array to see if it worked
print_r($my_array);
I believe the problem is here:
((isset($_POST["1pcCB"]))?implode(", ", $_POST["1pcCB"]):""))
and that this is not a pure array or some extra syntax is conflicting with the setting of this value to the new var ($a1)...
Anyone see the problem and can offer the solution?