How can PHP be used to retrieve specific values from a CSV file based on a given input?

To retrieve specific values from a CSV file based on a given input in PHP, you can read the CSV file line by line, explode each line by the delimiter (usually a comma), and check if the input matches the desired value in the line. If a match is found, you can extract the specific value you need.

<?php

$input = "John"; // Input value to search for
$csvFile = 'data.csv'; // Path to the CSV file

if (($handle = fopen($csvFile, 'r')) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) {
        if ($data[0] == $input) { // Assuming the first column contains the value to search for
            $specificValue = $data[1]; // Assuming the second column contains the specific value to retrieve
            echo "Specific value for input '$input' is: $specificValue";
            break;
        }
    }
    fclose($handle);
}
?>