codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php function startsWith($haystack, $needle) { $length = strlen($needle); return (substr($haystack, 0, $length) === $needle); } $A = array( 0 => '104-20_140.1', 1 => '104-10_136.1', 2 => '104-40_121.1', 3 => '104-41_122.1', 4 => '200-42_951.1', 5 => '200-43_952.1', 6 => '200-44_123.1', 7 => '200-45_124.1', 8 => '300-46_125.1', 9 => '300-47_126.1', 10 => '300-48_127.1', 11 => '300-49_128.1', 12 => '380-56_125.1', 13 => '380-57_126.1', 14 => '380-58_127.1', 15 => '380-59_128.1', ); $B = array( 0 => '200', 1 => '300' ); $C = array(); foreach ($A as $ka => $va) { foreach ($B as $kb => $vb) { if (startsWith($va, $vb)) { $C[] = $va; } } } print_r($C);
Private
[
?
]
Run code
Submit