-1

I get one value like "13and45" and would like to know if there is a way so I can store these values separately like

$string="13and45";    

$value1=13;    

$value2=45;    

Do you guys know how I can manipulate the string in order to get something like what I have above?

6

2 Answers 2

3

PHP - Explode () function

This will return an array with the two values.

Example:

$array = explode ("and", $string);

Returned array with strings:

$array[0] = 13
$array[1] = 45
Sign up to request clarification or add additional context in comments.

Comments

0

You can use something like intval(substr($string, 0, 2) to get the first integer and intval(substr($string, 5, 2) for the second. intval will get the integer value from a string, and substr will get the portion of the string given by ($string, index, length).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.