私が書いたコードがいくつかあり、それは本当にうまく機能します。私が書いたものが線形検索なのかバイナリ検索なのかわからない場合を除いて?! 私は違いについて本当に混乱しています。誰かに説明できるように、違いと私のコードを明確にしてもらえますか?
- 以下のコードは、ユーザーが入力した値を検索します。データのcsvファイルを通過します。次に、すべての値を結果を持つ新しい配列に保存します。うまくいけば、それは理にかなっています。
コードが線形かバイナリかを知りたいだけですか? 私はそれらについてとても混乱します*
$SearchThis = isset($_POST['Search']) ? $_POST['Search'] : '';
//empty()
$SearchThis = !empty($_POST['Search']) ? $_POST['Search'] : '';
// Grabs the csv file (and its existing data) and makes it into an array
$csv = array();
$lines = file('data/StaffData.csv', FILE_IGNORE_NEW_LINES);
foreach ($lines as $key => $value)
{
$csv[$key] = str_getcsv($value);
}
//A new array which will display the search results
$new_csv = array();
//This displays which rows have matched the search (it is put in an array)
//Looks through full names
$keys = array_keys(array_column($csv, 0), $SearchThis); // original code
foreach($keys as $index) { // Iterate over the keys
$new_csv[] = $csv[$index]; // Copy the matching rows to our new array
}
//Looks through phone numbers
$keys = array_keys(array_column($csv, 1), $SearchThis); // original code
foreach($keys as $index) { // Iterate over the keys
$new_csv[] = $csv[$index]; // Copy the matching rows to our new array
}
//Looks through gender
$keys = array_keys(array_column($csv, 2), $SearchThis); // original code
foreach($keys as $index) { // Iterate over the keys
$new_csv[] = $csv[$index]; // Copy the matching rows to our new array
}
//Looks through Birthday
$keys = array_keys(array_column($csv, 3), $SearchThis); // original code
foreach($keys as $index) { // Iterate over the keys
$new_csv[] = $csv[$index]; // Copy the matching rows to our new array
}
//Looks through Type of work
$keys = array_keys(array_column($csv, 4), $SearchThis); // original code
foreach($keys as $index) { // Iterate over the keys
$new_csv[] = $csv[$index]; // Copy the matching rows to our new array
}