Array (100-10, -50,200-20, 300-30, 30) asks for a match to the regular of all members of this array
Reply to discussion (solution)
$arr = Array (' 100-10 ', ' -50 ', ' 200-20 ', ' 300-30 ', ' -30 '); $b = Array (); foreach ($arr as $value) {if (Preg_match ("/[\d-]+/", $ Value, $match)) {Array_push ($b, $match);}} Var_dump ($b);
$arr = Array (' 100-10 ', ' -50 ', ' 200-20 ', ' 300-30 ', ' -30 '); $b = Array (); foreach ($arr as $value) {if (Preg_match ("/[\d-]+/", $ Value, $match)) {Array_push ($b, $match);}} Var_dump ($b);
Thanks, but it's not what I want.
That's what I need.
$arr =array (' 200-30 ', ' lsflsdf ', ' full field 50 percent ', ' 50-10 ', ' 100-30 ', '-50 ', ' 1000-100 ');
I need to assign different variables to separate the types of ' 200-30 ' or '-30 ' and other types.
By what distinction,--symbol?
$arr = Array (' 100-10 ', ' lsflsdf ', ' field 50 percent ', ' -50 ', ' 200-20 ', ' 300-30 ', ' -30 ', ' 1000-100 '); $a = array ();//Store other types $b = Array (); /store ' 200-30 ' or '-30 ' This type of foreach ($arr as $value) {if (Preg_match ("/^[\d-]+/", $value, $match)) {Array_push ($b, $match);} Else{array_push ($a, $value);}} Var_dump ($a, $b);//You can get two different types of results from each other.