Good morning,
I recommend you always look in the PHP documentation that is very complete and translated into Spanish.
In this case there is the function array_filter()
This can be passed up to three arguments
- The array to filter
- A callback (a function that will filter) optional
- A flag (this is explained further in the documentation) optional
And it returns an array with the elements that passed the filter
For what you require, we would use array_filter()
passing it the array and the callback in the following way:
$nuevoArray = array_filter(
[
0 => 1,
1 => 2,
2 => 4,
3 => 10,
4 => 7,
5 => 5,
6 => 10,
],
function ($elemento) {
return $elemento >= 6;
}
);
Now $nuevoArray
would have the elements that have a value >=
to 6
I hope this helps you and that you have explained me well, anything you tell me that I try to explain better or if I did not answer the answer.