Beispiel #1
0
<?php

require_once './includes/config.inc.php';
require_once './includes/functions.inc.php';
sleep(2);
// Don't touch this!
$key = (string) $_GET['data'];
if (file_exists(FACULTY_FILE)) {
    echo json_encode(searching($key));
} else {
    buildCSV();
    echo json_encode(searching($key));
}
//print_r($clean);
// for($i = 0; $i < 20; $i++){
// }
//var_dump($matches);
// Do any magic you want!
<?php

$names = ['Tina', 'Dana', 'Mike', 'Amy', 'Adam'];
$compare = ['Tina', 'Dean', 'Mel', 'Amy', 'Michael'];
function searching($needle, $haystack)
{
    return array_search($needle, $haystack);
}
$result = searching('Amy', $names);
if ($result !== false) {
    echo $names[$result] . " is in index {$result}" . PHP_EOL;
}
function comparing($names, $compare)
{
    $match = 0;
    foreach ($names as $name) {
        if (array_search($name, $compare) !== false) {
            $match++;
        }
    }
    return $match;
}
echo comparing($names, $compare) . PHP_EOL;