Copy PHP Array where elements are positive

后端 未结 4 1651
借酒劲吻你
借酒劲吻你 2021-01-26 22:24

trying to transfer one array with a combination of positive and negative numbers to a new array- but only where the elements are positive.

This is what I have so far:

4条回答
  •  囚心锁ツ
    2021-01-26 23:00

    $param = array(-1,2-,3,1,2,4,-1337);
    function positive_function($arr)
    {
        $temp = array();
        foreach ($arr as &$value) 
        {
            if($value > 0)
            {
                $temp[] = $value
            }
        }
           return $temp;
    }   
    

提交回复
热议问题