0

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?

Dimitar
  • 4,402
  • 4
  • 31
  • 47
André Marques
  • 180
  • 1
  • 15

2 Answers2

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
ozzy123lel
  • 41
  • 5
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).

Chris
  • 292
  • 2
  • 11