fork download
  1. <?php
  2. $collection = [];
  3. $arr = [
  4. ['tempo' => 30, 'id' => 1],
  5. ['tempo' => 20, 'id' => 2],
  6. ['tempo' => 100, 'id' => 3],
  7. ['tempo' => 120, 'id' => 4],
  8. ['tempo' => 4, 'id' => 5],
  9. ['tempo' => 19, 'id' => 6],
  10. ['tempo' => 300, 'id' => 7]
  11. ];
  12.  
  13. foreach($arr as $time) {
  14.  
  15. //quando for um tempo maior que 100 ele resetará para 100
  16. if($time['tempo'] > 100) {
  17. $time['tempo'] = 100;
  18. }
  19. //quando for um tempo menor que 20 ele pulará
  20. if($time['tempo'] < 20) {
  21. continue;
  22. }
  23.  
  24. $add = [
  25. 'tempo' => $time['tempo'],
  26. 'id' => $time['id']
  27. ];
  28. array_push($collection, $add);
  29.  
  30. }
  31. //pulou ids 5 e 6
  32. print_r($collection);
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [tempo] => 30
            [id] => 1
        )

    [1] => Array
        (
            [tempo] => 20
            [id] => 2
        )

    [2] => Array
        (
            [tempo] => 100
            [id] => 3
        )

    [3] => Array
        (
            [tempo] => 100
            [id] => 4
        )

    [4] => Array
        (
            [tempo] => 100
            [id] => 7
        )

)