T
T
Tereverda2019-12-10 22:20:23
PHP
Tereverda, 2019-12-10 22:20:23

Substituting values ​​in PHP's min() function?

Several variables are given in the class, some of them can be NULL, such a result is given by the function, if there is something in the request that it does not support.
When I have collected all the variables, they need to be compared and give the smallest value = the optimal supplier according to business logic.
// get the values ​​of the variables
// check for NULL
// pushes anything that is not NULL into the min() function;
// return minimum value = best supplier
allowed:
$banan = 10;
$appleko = 12;
$tomat = NULL; because the supplier cannot deliver this product.
next comes min($banan, $yabloko, $tomat); // 10, 12, NULL
the result will naturally be NULL because it is the smallest, but it needs to return 10.
At the first stage, it is easy to sort the values ​​with the is_null() function;
But how to set specific existing variables for the min() function?
For the query to be min($banan, $yabloko);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
4
4iloveg, 2019-12-10
@Tereverda

If indeed suppliers are contained in variables, then put them into an array with the compact() function, then filter array_filter() leaving numbers and pass them to min()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question