Convert string to array

Asked

Viewed 93 times

3

Guys I get data from my database that comes 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 show each one separately without comma or anything,?

  • The answer worked out for you Vinicius?

  • 1

    Yes! I managed to perform my task, sorry I didn’t update the question yet..

1 answer

5


Thus:

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

Example: Ideone

Browser other questions tagged

You are not signed in. Login or sign up in order to post.