I need to be able to match up arrays, based on instances of row values and only return 1 result.
I'm not sure if i'm phrasing that right, so let me explain.
For example, lets say I have 2 arrays
$people = array(
array(
'name' => 'Joe',
'DOB' => '01/01/1990'
),
array(
'name' => 'John',
'DOB' => '01/01/1990'
),
array(
'name' => 'Jane',
'DOB' => '01/01/1990'
)
);
$sales = array(
array(
'name' => 'Car',
'price' => '1000.00',
'note' => 'This sale was made by Joe Bloggs'
),
array(
'name' => 'Car 2',
'price' => '2000.00',
'note' => 'Joe Bloggs sold this car today'
),
array(
'name' => 'Car 3',
'price' => '3000.00'
'note' => 'Jane Smith sold our most expensive car'
)
);
foreach($people as $personKey => $person){
foreach($sales as $saleKey => $sale){
if($sale['name'] == $person['name']){
if($sale['price'] > 1000.00){
$person[$personKey]['highestSale'] == $saleKey;
} else {
$person[$personKey]['highestSale'] == $saleKey;
}
}
}
}
I want to be able to run the foreach loop, but achieve 2 things with it
I need to be able to search the second foreach loop, by the current first name only. I need it to be able to search the
$sales['seller']
string and match it if it contains the$people['name']
(Joe will match with Joe Bloggs).I also need it to take priority of the first result only in this loop. So the
if($sale['price'] > 1000.00)
is true, exit this instance of the person loop, and move on to the next person (only return 1 result/match for each person);
At the moment it would return
"Joe's highest sale is £2000.00"
"Joe's highest sale is £1000.00"
"Jane's highest sale is £3000.00"
"John's highest sale is £0.00"
Inside the loop, where the if statement runs, I need it to exit the current loop if the if
statement is true and move onto the next row, so my result will look like this instead.
"Joe's highest sale is £2000.00"
"Jane's highest sale is £3000.00"
"John's highest sale is £0.00"
I'm sorry if this doesn't make sense, its quite hard to explain what it is i'm trying to achieve! If anything needs to be re-explained, please ask.