Copy PHP Array where elements are positive

后端 未结 4 1694
借酒劲吻你
借酒劲吻你 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 22:54

    try:

    $param = array(2, 3, 4, -2, -3, -5);
    
    $positive = array_filter($param, function ($v) {
      return $v > 0;
    });
    
    print_r($positive);
    

    http://codepad.viper-7.com/eKj7pF

提交回复
热议问题