I’m trying to teach myself PHP by using online resources. One of the new things I’m learning is arrays. I’m having trouble with writing a function to return an array. One problem I’m trying solve is writing a function to return the name of a customer and if they bought more than $200 worth of groceries by using given the array structure provided. The array structure is below. I also shown the code I have written so far below.
$customers = [ 1 => [ 'name' => 'Tim',
'orders' => [ '52.99', '155.32', '210.25'],
],
2 => ['name' => 'Mary',
'orders' => ['211.38', '32.92','115.72'],
],
];
echo (getTotal($customers));
function getTotal ($array = []) {
$result = array();
foreach ($result as $customer){
if ($value['price'] > 200) {
$result[] = $customer;
}
}