Convert string to array

Posted on

Question :

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?

    

Answer :

Like this:

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

Example Ideone

>
    

Leave a Reply

Your email address will not be published. Required fields are marked *