Reputation: 593
I have a question variable e.g. "4X9"
how can i split this into 3 different variables, to have an integer 4, integer 9 and string X ?
I tried using
$arr = explode('X', $question);
$before = $arr[0];
$bbefore = str_replace('"', "", $before);
$newBefore =(int)$before;`
and the same for after.
Upvotes: 0
Views: 57
Reputation: 219814
list($before, $x, $after) = str_split(str_replace('"', '', $question));
Explode string by character using str_split()
Use list()
to make assigning them variables clearer
If $before
and/or $after
are integers you can cast them after this line of code
list($before, $x, $after) = str_split(str_replace('"', '', $question));
$before = (int) $before;
$after = (int) $after;
Upvotes: 3