php - Apply column min and column max to every row in a 2d array
I need to find the minimum value in one column and the maximum value in another column of a two-dimensional array and apply those values to every row in the array.
Sample input:
{-code-{-code-3}}
In the above data set, the minimumday1
value is{-code-3}
and the maximumday2
value is3
. I need to apply those two values (respective to their column) to theday1
andday2
values in every rows.
Expected output:
[
["day1" => {-code-3}, "day2" => 3, "name" => "Ram"],
["day1" => {-code-3}, "day2" => 3, "name" => "Raj"],
["day1" => {-code-3}, "day2" => 3, "name" => "Rahul"],
["day1" => {-code-3}, "day2" => 3, "name" => "Rocky"]
]
Answer
Solution:
This will help -
Output
Answer
Solution:
this will help: check the demo
Answer
Solution:
Instead of using multiple cycles (
foreach()
loops and orarray_column()
calls), this task can be completed in 1 cycle by declaring reference variables at all elements which need to be updated with the min/max values.Below, the final iteration's
$day1
and$day2
values will be distributed to all points of reference.Code: (Demo)