Array of strings to array of words

I have data in my mysql database "Service, House Worker" (without "") when I access my data from the database I found (Service, House Worker) as it is when I try to convert from using var_dump(explode(',',($CheckBoxAnswer)));

), then it is returned as follows:

array(1) { [0]=> string(26) "Service,House Worker" }

      

but I want something like this:

array(1)
(
    [0] => string(7) "Service"
    [1] => string(13) "House Worker"
)

      

$CheckBoxAnswer

contains the data that I pulled from mysql. i tried using var_dump(explode(',',($CheckBoxAnswer)));

but its not working

+3


source to share


2 answers


Try the following:

  var_dump(explode(',',($CheckBoxAnswer[0])));

      



You are trying to explode an array into another array. Instead, you need to specify a string.

+1


source


First you need to trim $CheckBoxAnswer

Because using var_dump giving line length 26 instead of 20

Then after using the string, replace



str_replace('/','',$CheckBoxAnswer);

      

After that, try using var_dump(explode(',',($CheckBoxAnswer)));

0


source







All Articles