A simple PHP program that reads an orders CSV file and outputs:
- Total revenue (sum of quantity × price)
- Best-selling SKU (the product with the highest total quantity)
- PHP 7.4 or higher
Check with:
php -v├── analyze.php # Main script (run this)
├── src/
│ └── CsvOrderAnalyzer.php # Core logic
├── allsome_interview_test_orders.csv # Sample input data
├── output.json # Generated after running
└── README.md
cd /path/to/your-project-folder
php analyze.phpTo use a different CSV file:
php analyze.php path/to/your_orders.csvYour CSV file needs these columns (order doesn't matter):
order_id,sku,quantity,price
1001,SKU-A123,2,50.00
1002,SKU-B456,1,75.00
The program prints JSON to the console and saves it to output.json:
{
"total_revenue": 975,
"best_selling_sku": {
"sku": "SKU-C789",
"total_quantity": 7
}
}- File not found → shows error and exits
- Missing columns → shows which columns are missing
- Bad rows (empty SKU, invalid numbers) → row is skipped with a warning, rest of the file still processes
- No valid data → shows error and exits