Reputation:
i have the following array with 10,000+ entries
1895] => CHQ N SUMEET KHUITAN DEP BY VAIBHAV MONEY TRANS
[1896] => CR
[1897] => 85,000.00 Not Available Not Available Not Available Not Available TCI 01/12/13 01/12/13
[1898] =>
[1899] => 2 S32324176 01/12/13
[1900] =>
[1901] => <444209603509>MY FINANCE LTD
[1902] => CR
[1903] => 8,00,000.00 Not Available Not Available Not Available Not Available TBI 01/12/13 01/12/13
[1904] =>
[1905] => 2 S32323871 01/12/13
[1906] =>
[1907] => EARTH SUB REMIT, BOHORA TAR
[1908] => CR
[1909] => 2,00,000.00 Not Available Not Available Not Available Not Available TCI 01/12/13 01/12/13
[1910] =>
[1911] => 1319 S32321414 01/12/13
[1912] => 1000786233
[1913] => INWARD CLEARING NPR
[1914] => DR
[1915] => 1,00,00,000.00 Not Available Not Available Not Available Not Available LI 01/12/13 01/12/13
[1916] =>
[1917] => 2 DC9032 01/12/13
[1918] =>
[1919] => HAMRO BIKASH BANK
[1920] => CR
[1921] => 13,00,000.00 Not Available Not Available Not Available Not Available TCI 01/12/13 01/12/13
[1922] =>
[1923] => 1 DC7192 01/12/13
[1924] =>
[1925] => SP TRADING CASH DEPOSIT
[1926] => CR
[1927] => 36,140.00 Not Available Not Available Not Available Not Available CNR 01/12/13 01/12/13
[1928] =>
[1929] => 2 S32318770 01/12/13
[1930] =>
[1931] => <444990698490>good FINANCE LTD
[1932] => CR
[1933] => 35,00,000.00 Not Available Not Available Not Available Not Available TBI 01/12/13 01/12/13
From this entries i want consider the array which start with '<' preserving their original index
i.e
[1901] => <444209603509>MY FINANCE
[1931] => <444990698490>good FINANCE
i did the folowing
foreach($arr as $key=>$val){
if(substr($val,0,1)=='<')
$new_arr[$key]=$val;
}
print_r($new_arr);
I really slowed down the script, dont we have any alternative like array_filter
Upvotes: 0
Views: 120
Reputation: 6344
Try array_filter in PHP. The function checks whether the array value starts with <
.
function myFilter($val){
$val = trim($val);
return ($val[0]==='<');
}
array_filter($array,'myFilter');
Upvotes: 1