-1

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?

user892134
  • 3,078
  • 16
  • 62
  • 128

2 Answers2

1

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

jthawme
  • 223
  • 1
  • 10
0

Something like this?

<?php
$array = array();
$array_2 = array();

$array[0] = 120;
$array[1] = 140;

$array_2[0] = 110;
?>