note 128803 added to language.operators.comparison

From: Date: Tue, 15 Aug 2023 06:15:45 +0000
Subject: note 128803 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-220764@lists.php.net to get a copy of this message
Between the "shortcut ternary" (aka "elvis") and "spaceship" operators, you can write some quite compact comparison functions for usort and its ilk. If you want to sort an array of associative arrays by several different keys you can chain them in the same way that you can list column names in an SQL ORDER BY clause. <?php usort($array, fn($a, $b) => $a['a'] <=> $b['a'] ?: $b['b'] <=> $a['b'] ?: $a['c'] <=> $b['c']); ?> Will sort the array by column 'a', then by column 'b' descending, then by column 'c'; or in SQL-speak 'ORDER BY a, b DESC, c". ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 222.153.168.209) ---- Manual Page -- https://php.net/manual/en/language.operators.comparison.php Edit -- https://main.php.net/note/edit/128803 Del: integrated -- https://main.php.net/note/delete/128803/integrated Del: useless -- https://main.php.net/note/delete/128803/useless Del: bad code -- https://main.php.net/note/delete/128803/bad+code Del: spam -- https://main.php.net/note/delete/128803/spam Del: non-english -- https://main.php.net/note/delete/128803/non-english Del: in docs -- https://main.php.net/note/delete/128803/in+docs Del: other reasons-- https://main.php.net/note/delete/128803 Reject -- https://main.php.net/note/reject/128803 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220764) next »