<?php
$arr1 = array(
"6263888445",
"3134003757",
"985415628" // should be moved to another array
);
$arr2 = array();
//preg_match('/^[0-9]{10}$/'), $var);
I want to use that reg ex to move anything that fails to $arr2
How about you sort the array, and anything less than 1000000000 or strlen === 10 you move to the other array?
$arr1 = array(
"6263888445",
"3134003757",
"100",
"985415628", "1",
);
$arr2 = array();
sort($arr1);
foreach( $arr1 as $k => $a){
if ( strlen($a) < 10 ){
$arr2[] = $a ;
unset($arr1[$k]);
}
if(strlen($a) === 10) continue ; // drop out of the loop as soon as a 10 figure amt is found
}
var_dump($arr1);
var_dump($arr2);
EDIT
This way you avoid having to run a regex in a loop, and you only perform the check on the top part of the sorted array, when it discovers a 10 char figure it quits.