how can i get this 2 variables? The $ingredients must get real price from $price, it must get name and price for example TV is amount 3 and price is 20, so it's 60. Here is code.
$ingredients = [
['name' => 'TV', 'amount' => 3],
['name' => 'LAPTOP', 'amount' => 2],
['name' => 'HAREM', 'amount' => 2],
['name' => 'OIL', 'amount' => 1],
['name' => 'Windows', 'amount' => 1],
['name' => 'Something', 'amount' => 1]
];
$prices = [
'TV' => 20,
'LAPTOP' => 20,
'HAREM' => 25,
'OIL' => 20,
'Windows' => 25,
'Something' => 35
];
With array_column you get all the 'name' from the array.
This 'name' array can then be searched with array_search to get the key where 'item' is.
Array_search returns false if not found, keep that in mind. 'false' == 0 in PHP.
$name = array_column($ingredients,"name");
Foreach($prices as $item => $price){
$find = array_search($item, $name);
If($find !== false) $res[$item] = $price * $ingredients[$find]['amount'];
}
Var_dump($res);