I have these two pieces of text
120 - 140 (cm)
and
110 (cm)
I'd like to store the values into an array like
$array[0] = 120
$array[1] = 140
$array_2[0] = 110
How would i do this?
I have these two pieces of text
120 - 140 (cm)
and
110 (cm)
I'd like to store the values into an array like
$array[0] = 120
$array[1] = 140
$array_2[0] = 110
How would i do this?
You could do
function numArray($str)
{
$str = preg_replace("/[^0-9,.]/", " ", $str);
return preg_split('/ /', $str, -1, PREG_SPLIT_NO_EMPTY);
}
$str = "120 - 140 (cm)";
$array = numArray($str);
That will return an array with only numbers in it
Something like this?
<?php
$array = array();
$array_2 = array();
$array[0] = 120;
$array[1] = 140;
$array_2[0] = 110;
?>