How can PHP be used to calculate the lowest market price within a specific time range from an array of data?

To calculate the lowest market price within a specific time range from an array of data in PHP, you can iterate over the array, filter the data based on the time range, and then find the minimum price value within that filtered data set.

<?php

// Sample array of market data with timestamps and prices
$marketData = [
    ['timestamp' => '2022-01-01 08:00:00', 'price' => 100],
    ['timestamp' => '2022-01-01 09:00:00', 'price' => 90],
    ['timestamp' => '2022-01-01 10:00:00', 'price' => 80],
    ['timestamp' => '2022-01-01 11:00:00', 'price' => 70],
];

// Define the time range
$startTime = '2022-01-01 09:00:00';
$endTime = '2022-01-01 11:00:00';

// Filter the data based on the time range
$filteredData = array_filter($marketData, function($data) use ($startTime, $endTime) {
    return $data['timestamp'] >= $startTime && $data['timestamp'] <= $endTime;
});

// Find the minimum price within the filtered data set
$lowestPrice = min(array_column($filteredData, 'price'));

echo "The lowest market price within the time range is: $lowestPrice";

?>