Search code examples
phpexplode

Explode to array and print each element as list item?


I have a set of numbers in a table field in database, the numbers are separated by comma '|1||10||12|'. I am trying to do the following:

$array =  explode('|', $set_of_numbers);

answer

["","1","","10","","12",""]

I need so

["1","10","12"]

as can be done thank you for previously


Solution

  • Try this

    $array = trim($array, '|');
    $array = explode('||', $set_of_numbers);