Convert string to array

3

I get data from my database that comes in this way 1,2,3,4,5 and I need to run each number, because each number is a user ID and I want it to display each separately without a comma or anything, I tried to give foreach But I could not, how can I?

    
asked by anonymous 21.06.2014 / 17:06

1 answer

5

Like this:

<?php     
    $numeros = '1,2,3,4,5';
    $num = explode(',', $numeros);
    foreach($num as $n){
       echo $n;
       echo PHP_EOL;
    }

Example Ideone

>     
21.06.2014 / 17:10