[ create a new paste ] login | about

Link: http://codepad.org/FlUMOHgh    [ raw code | output | fork ]

PHP, pasted on Sep 8:
<?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);


Output:
1
2
3
4
5
6
7
8
9
10
11
Array
(
    [0] => 200-42_951.1
    [1] => 200-43_952.1
    [2] => 200-44_123.1
    [3] => 200-45_124.1
    [4] => 300-46_125.1
    [5] => 300-47_126.1
    [6] => 300-48_127.1
    [7] => 300-49_128.1
)


Create a new paste based on this one


Comments: