Read one string into two strings

Within PHP, how can take a variable containing "1_approved" and move it into two variables with the first variable containing "1" and the second variable containing "approved"?
PeterErhardAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
please try this:

 list($var1, $var2) = explode("_", $yourvariable);
0
 
nizsmoDeveloperCommented:
One way of doing this below:
<?php
    $myvariable = "1_approved";
    $variableArray = explode("_",$myvariable);
    $variableNumber = $variableArray[0];
    $variableText = $variableArray[1];
    
    echo $variableNumber . "<br>";
    echo $variableText;
?>

Open in new window

0
 
nizsmoDeveloperCommented:
sorry angellll did not see your post before i posted.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.