Writing a function to return an array

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;
}
}

Is that a single order with multiple items or multiple orders for a person?

Are you wanting over $200 in a single amount or over $200 with all amounts combined for a person?

Multiple orders for a person. I’m trying to find which costed the customer more than $200,

<?php
$customers = [
    1 => [
        'name' => 'Tim',
        'orders' => ['52.99', '155.32', '210.25'],
    ],
    2 => [
        'name' => 'Mary',
        'orders' => ['211.38', '32.92', '115.72'],
    ],
];

foreach ($customers as $customer) {
    foreach ($customer['orders'] as $order) {
        if ($order > 200) {
            echo $customer['name'] . ' has an order over $200. Total: $' . $order . "<br>";
        }
    }
}
Sponsor our Newsletter | Privacy Policy | Terms of Service