How can PHP be used to search for partial matches in a JSON file, rather than exact matches?

To search for partial matches in a JSON file using PHP, you can read the JSON file, decode it into an array, and then loop through the array to check for partial matches using functions like strpos or stripos. You can also use regular expressions to search for patterns within the JSON data.

<?php

// Read the JSON file
$jsonData = file_get_contents('data.json');

// Decode the JSON data into an array
$data = json_decode($jsonData, true);

// Search for partial matches
$searchTerm = 'partial_match';
foreach ($data as $item) {
    foreach ($item as $key => $value) {
        if (stripos($value, $searchTerm) !== false) {
            echo "Partial match found in key: $key, value: $value\n";
        }
    }
}

?>