Q:
get values in an order from a list into the array php
I have this problem that I can't seem to find a simple solution for.
I have a list that shows out values that have a result higher than 7 and want to store them in an array of values that are higher than 7 in an order.
for example:
[0] = 8
[1] = 5
[2] = 9
How do I do that?
Thanks in advance
A:
You have to create a function that iterate in your array and look for the values greater than 7, with array_filter it is very simple:
function greaterThan7(&$array,$value)
{
foreach ($array as &$value)
{
if ($value > 7)
{
$array[] = $value;
}
}
return $array;
}
$array = array(8,5,9);
$array = array_filter($array, 'greaterThan7');
var_dump($array);
But you should use a loop for this:
7)
//array_filter will not work as array_filter return the filtered array
The $value argument must be the old value, so I used &$value in the function.
Q:
Visual Studio extensions
Related links:
留言