3
21/10/2024 1:34 pm
Topic starter
- Read an array of integers
- Remove all negative numbers from it and print the remaining elements in reversed order
- In case of no elements left in the array, print "empty"
1 Answer
2
21/10/2024 1:35 pm
My solution:
<?php $arr = array_map(function ($element) { return ($element > 0) ? $element : false; }, explode(" ", readline())); $arr = array_filter($arr); $arr = array_reverse($arr); if (count($arr) > 0) { echo implode(" ", $arr); } else { echo "empty"; }