[PHP-NOTES] note 130423 added to function.array-map

[email protected] ("[email protected]") Mon, 21 Jul 2025 21:28:07 +0000 (UTC)
Newsgroups php.notes
Message-ID <[email protected]>
<?php 

function highAndLow(string $numbers): string {

    // Split the input string into an array using spaces as delimiter
    // Then filter out any non-numeric values
    $numbers = array_filter(explode(" ", $numbers), 'is_numeric');

    // Convert the remaining numeric strings to integers
    $ints = array_map('intval', $numbers);

    // Return the highest and lowest numbers, separated by a space
    return max($ints) . " " . min($ints);
}

// Example usage: will output "388 2"
echo(highAndLow(' 2 388  asdfgh 4'));

?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 2c0f:f888:a180:9bf:b889:79ad:9438:8efe)
----
Manual Page -- https://php.net/manual/en/function.array-map.php
Edit        -- https://main.php.net/note/edit/130423
Del: integrated  -- https://main.php.net/note/delete/130423/integrated
Del: useless     -- https://main.php.net/note/delete/130423/useless
Del: bad code    -- https://main.php.net/note/delete/130423/bad+code
Del: spam        -- https://main.php.net/note/delete/130423/spam
Del: non-english -- https://main.php.net/note/delete/130423/non-english
Del: in docs     -- https://main.php.net/note/delete/130423/in+docs
Del: other reasons-- https://main.php.net/note/delete/130423
Reject      -- https://main.php.net/note/reject/130423
Search      -- https://main.php.net/manage/user-notes.php