Skip to content
Advertisement

How to make one variable to multiple variables using php?

How to assign one variable to multiple variables using php? Example:

$student = "Peter and Mary";

I want to get “Peter” and “Mary” string on the $student.

how to make the $student become two variable?? I hope the I can get the final result is

$var_name1 ="Peter";
$var_name2 ="Mary";

Is it using str_contains or str_replace?????

Thank you very much

Advertisement

Answer

$student = "Peter and Mary";
$student_arr = explode("and",$student);
print_r($student_arr);

output => $student_arr[0] = “Peter”; $student_arr[1] = “Mary”;

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement