diff --git a/core/lib/Drupal/Component/Utility/SortArray.php b/core/lib/Drupal/Component/Utility/SortArray.php
index 2ef6223f73d21ea9c6ee7ff3365f9990dbaae068..6c1c9180249340f4b67d066bd7492b6b3a26f4e5 100644
--- a/core/lib/Drupal/Component/Utility/SortArray.php
+++ b/core/lib/Drupal/Component/Utility/SortArray.php
@@ -122,11 +122,7 @@ public static function sortByKeyInt($a, $b, $key) {
     $a_weight = (is_array($a) && isset($a[$key])) ? $a[$key] : 0;
     $b_weight = (is_array($b) && isset($b[$key])) ? $b[$key] : 0;
 
-    if ($a_weight == $b_weight) {
-      return 0;
-    }
-
-    return ($a_weight < $b_weight) ? -1 : 1;
+    return $a_weight <=> $b_weight;
   }
 
 }
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
index 9b60c70daeb7ec82f05f06b87cadb16fdf6350b8..72a90545e32bf7368e1cfdf2f79cecb55c3e9aaf 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
@@ -235,7 +235,7 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
       $b_label = $b->label() ?? '';
       return strnatcasecmp($a_label, $b_label);
     }
-    return ($a_weight < $b_weight) ? -1 : 1;
+    return $a_weight <=> $b_weight;
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php
index 5c4068d0505d63e7d9a47fc3849fb98c70e171fc..b1efc6bb07813a2cf90d3d565cfb571f003fc7db 100644
--- a/core/lib/Drupal/Core/Language/Language.php
+++ b/core/lib/Drupal/Core/Language/Language.php
@@ -160,7 +160,7 @@ public static function sort(&$languages) {
         }
         return strnatcasecmp($a_name, $b_name);
       }
-      return ($a_weight < $b_weight) ? -1 : 1;
+      return $a_weight <=> $b_weight;
     });
   }
 
diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php
index 1bd1cc2380670274be9638483bdc9e50678e789b..24c6f6ea057599a050eaf7fc1425df166068a7c9 100644
--- a/core/lib/Drupal/Core/Routing/RouteProvider.php
+++ b/core/lib/Drupal/Core/Routing/RouteProvider.php
@@ -392,7 +392,7 @@ protected function routeProviderRouteCompare(array $a, array $b) {
     }
     // Reverse sort from highest to lowest fit. PHP should cast to int, but
     // the explicit cast makes this sort more robust against unexpected input.
-    return (int) $a['fit'] < (int) $b['fit'] ? 1 : -1;
+    return (int) $b['fit'] <=> (int) $a['fit'];
   }
 
   /**
diff --git a/core/modules/filter/src/FilterPluginCollection.php b/core/modules/filter/src/FilterPluginCollection.php
index 81ebddf4728f17f96ed969e7d1f52698c665da0d..31386ed786345bcfdfe7a9b06e90ebdaa81d43c8 100644
--- a/core/modules/filter/src/FilterPluginCollection.php
+++ b/core/modules/filter/src/FilterPluginCollection.php
@@ -94,7 +94,7 @@ public function sortHelper($aID, $bID) {
       return !empty($a->status) ? -1 : 1;
     }
     if ($a->weight != $b->weight) {
-      return $a->weight < $b->weight ? -1 : 1;
+      return $a->weight <=> $b->weight;
     }
     if ($a->provider != $b->provider) {
       return strnatcasecmp($a->provider, $b->provider);
diff --git a/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php b/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php
index c604d650ae466ff57483dfce924553966af4d45d..566aa1e3c9645edae507e734fd0b5368d7d67ad2 100644
--- a/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php
+++ b/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php
@@ -183,7 +183,7 @@ protected function getPlugins() {
         $a_label = (string) $a->getLabel();
         $b_label = (string) $b->getLabel();
         if ($a_label === $b_label) {
-          return $a->getPluginId() < $b->getPluginId() ? -1 : 1;
+          return $a->getPluginId() <=> $b->getPluginId();
         }
         return strnatcasecmp($a_label, $b_label);
       });
diff --git a/core/modules/image/src/ImageEffectPluginCollection.php b/core/modules/image/src/ImageEffectPluginCollection.php
index 25ee6f2a268d68c94a8276eecc9719066528e726..a32975f9368dfbfda7271a37f7a91f4c95b1ecd1 100644
--- a/core/modules/image/src/ImageEffectPluginCollection.php
+++ b/core/modules/image/src/ImageEffectPluginCollection.php
@@ -22,13 +22,7 @@ public function &get($instance_id) {
    * {@inheritdoc}
    */
   public function sortHelper($aID, $bID) {
-    $a_weight = $this->get($aID)->getWeight();
-    $b_weight = $this->get($bID)->getWeight();
-    if ($a_weight == $b_weight) {
-      return 0;
-    }
-
-    return ($a_weight < $b_weight) ? -1 : 1;
+    return $this->get($aID)->getWeight() <=> $this->get($bID)->getWeight();
   }
 
 }
diff --git a/core/modules/language/src/HttpKernel/PathProcessorLanguage.php b/core/modules/language/src/HttpKernel/PathProcessorLanguage.php
index 9feae277c7f87c81ea026990f76885a12f03806e..512f22bde920355fa2b50abb03c2aac74a97235b 100644
--- a/core/modules/language/src/HttpKernel/PathProcessorLanguage.php
+++ b/core/modules/language/src/HttpKernel/PathProcessorLanguage.php
@@ -147,14 +147,7 @@ protected function initProcessors($scope) {
     // Sort the processors list, so that their functions are called in the
     // order specified by the weight of the methods.
     uksort($this->processors[$scope], function ($method_id_a, $method_id_b) use ($weights) {
-      $a_weight = $weights[$method_id_a];
-      $b_weight = $weights[$method_id_b];
-
-      if ($a_weight == $b_weight) {
-        return 0;
-      }
-
-      return ($a_weight < $b_weight) ? -1 : 1;
+      return $weights[$method_id_a] <=> $weights[$method_id_b];
     });
   }
 
diff --git a/core/modules/layout_builder/src/Section.php b/core/modules/layout_builder/src/Section.php
index cd27437cb2f6d38df9ad81f174d0f18fd85c1811..e87bb7c305511ddcfd034effb1dd5f17f5500a93 100644
--- a/core/modules/layout_builder/src/Section.php
+++ b/core/modules/layout_builder/src/Section.php
@@ -258,7 +258,7 @@ public function getComponentsByRegion($region) {
       return $component->getRegion() === $region;
     });
     uasort($components, function (SectionComponent $a, SectionComponent $b) {
-      return $a->getWeight() > $b->getWeight() ? 1 : -1;
+      return $a->getWeight() <=> $b->getWeight();
     });
     return $components;
   }
diff --git a/core/modules/search/src/Entity/SearchPage.php b/core/modules/search/src/Entity/SearchPage.php
index 9d6e3980c86904fa9deee6fc772dee54fe1b450e..91cc93960f9f156c485be8faf6b185954790acfc 100644
--- a/core/modules/search/src/Entity/SearchPage.php
+++ b/core/modules/search/src/Entity/SearchPage.php
@@ -216,7 +216,7 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
     $a_status = (int) $a->status();
     $b_status = (int) $b->status();
     if ($a_status != $b_status) {
-      return ($a_status > $b_status) ? -1 : 1;
+      return $b_status <=> $a_status;
     }
     return parent::sort($a, $b);
   }
diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php
index 0cca92e2d97acb8c561e7c12e4c4e4c95bed3957..7aeb4a6fa6ae3dfd81bd36d0dda320b5ec7e4062 100644
--- a/core/modules/shortcut/src/Entity/Shortcut.php
+++ b/core/modules/shortcut/src/Entity/Shortcut.php
@@ -185,7 +185,7 @@ public static function sort(ShortcutInterface $a, ShortcutInterface $b) {
     if ($a_weight == $b_weight) {
       return strnatcasecmp($a->getTitle(), $b->getTitle());
     }
-    return ($a_weight < $b_weight) ? -1 : 1;
+    return $a_weight <=> $b_weight;
   }
 
 }
diff --git a/core/modules/tour/src/Entity/Tour.php b/core/modules/tour/src/Entity/Tour.php
index feca0585b010e35b056dc584000ae3be98b9b1c5..032817a91293ba8f6656b5301d19adbdabeb49d4 100644
--- a/core/modules/tour/src/Entity/Tour.php
+++ b/core/modules/tour/src/Entity/Tour.php
@@ -123,10 +123,7 @@ public function getTips() {
       $tips[] = $this->getTip($id);
     }
     uasort($tips, function ($a, $b) {
-      if ($a->getWeight() == $b->getWeight()) {
-        return 0;
-      }
-      return ($a->getWeight() < $b->getWeight()) ? -1 : 1;
+      return $a->getWeight() <=> $b->getWeight();
     });
 
     \Drupal::moduleHandler()->alter('tour_tips', $tips, $this);
diff --git a/core/modules/views/src/ViewsData.php b/core/modules/views/src/ViewsData.php
index af44e691bacf0793304e50b544479169ab97da4b..bcbab7bce30bfa1e370b295270fd2533cad0b2a7 100644
--- a/core/modules/views/src/ViewsData.php
+++ b/core/modules/views/src/ViewsData.php
@@ -304,12 +304,9 @@ public function fetchBaseTables() {
     // Sorts by the 'weight' and then by 'title' element.
     uasort($tables, function ($a, $b) {
       if ($a['weight'] != $b['weight']) {
-        return $a['weight'] < $b['weight'] ? -1 : 1;
+        return $a['weight'] <=> $b['weight'];
       }
-      if ($a['title'] != $b['title']) {
-        return $a['title'] < $b['title'] ? -1 : 1;
-      }
-      return 0;
+      return $a['title'] <=> $b['title'];
     });
 
     return $tables;
diff --git a/core/modules/views/src/ViewsDataHelper.php b/core/modules/views/src/ViewsDataHelper.php
index da4f7f1c3b57380b90a3a545e10e545322f4fe3e..c977882d9b47f4525634f5ed0b6b7dcb4e662fd6 100644
--- a/core/modules/views/src/ViewsDataHelper.php
+++ b/core/modules/views/src/ViewsDataHelper.php
@@ -176,16 +176,12 @@ protected static function fetchedFieldSort($a, $b) {
     $a_group = mb_strtolower($a['group']);
     $b_group = mb_strtolower($b['group']);
     if ($a_group != $b_group) {
-      return $a_group < $b_group ? -1 : 1;
+      return $a_group <=> $b_group;
     }
 
     $a_title = mb_strtolower($a['title']);
     $b_title = mb_strtolower($b['title']);
-    if ($a_title != $b_title) {
-      return $a_title < $b_title ? -1 : 1;
-    }
-
-    return 0;
+    return $a_title <=> $b_title;
   }
 
 }
diff --git a/core/modules/views/tests/src/Functional/ViewTestBase.php b/core/modules/views/tests/src/Functional/ViewTestBase.php
index c5fc8d75e223caaf6f2699d67d49f939860bb562..beebadba2fe5bbe002356d431dfa656414ea518e 100644
--- a/core/modules/views/tests/src/Functional/ViewTestBase.php
+++ b/core/modules/views/tests/src/Functional/ViewTestBase.php
@@ -80,10 +80,7 @@ protected function enableViewsTestModule() {
   protected function orderResultSet($result_set, $column, $reverse = FALSE) {
     $order = $reverse ? -1 : 1;
     usort($result_set, function ($a, $b) use ($column, $order) {
-      if ($a[$column] == $b[$column]) {
-        return 0;
-      }
-      return $order * (($a[$column] < $b[$column]) ? -1 : 1);
+      return $order * ($a[$column] <=> $b[$column]);
     });
     return $result_set;
   }
diff --git a/core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php b/core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php
index 6d76bbd1501ef62bedde284d019340bf2f8dd7d4..e3af4551378bb10beb7969bf32f67aad7e467c7d 100644
--- a/core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php
+++ b/core/modules/views/tests/src/Kernel/ViewsKernelTestBase.php
@@ -108,10 +108,7 @@ protected function setUpFixtures() {
   protected function orderResultSet($result_set, $column, $reverse = FALSE) {
     $order = $reverse ? -1 : 1;
     usort($result_set, function ($a, $b) use ($column, $order) {
-      if ($a[$column] == $b[$column]) {
-        return 0;
-      }
-      return $order * (($a[$column] < $b[$column]) ? -1 : 1);
+      return $order * ($a[$column] <=> $b[$column]);
     });
     return $result_set;
   }
diff --git a/core/modules/views/views.views.inc b/core/modules/views/views.views.inc
index b7e9f8c392f9923abb83e6f29604ea734b762aae..7c236e68c4cbd29323bde952daf75712b1107129 100644
--- a/core/modules/views/views.views.inc
+++ b/core/modules/views/views.views.inc
@@ -280,7 +280,7 @@ function views_entity_field_label($entity_type, $field_name) {
     if ($label_counter[$a] === $label_counter[$b]) {
       return strcmp($a, $b);
     }
-    return $label_counter[$a] > $label_counter[$b] ? -1 : 1;
+    return $label_counter[$b] <=> $label_counter[$a];
   });
   $label_counter = array_keys($label_counter);
   return [$label_counter[0], $all_labels];
diff --git a/core/modules/views_ui/src/Form/Ajax/ReorderDisplays.php b/core/modules/views_ui/src/Form/Ajax/ReorderDisplays.php
index 38ed4e67e09f8bb99e07756110c43e0e3138687c..695f478b21c9e8bf0d4ae565c4d2605c5e9c5da9 100644
--- a/core/modules/views_ui/src/Form/Ajax/ReorderDisplays.php
+++ b/core/modules/views_ui/src/Form/Ajax/ReorderDisplays.php
@@ -52,10 +52,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
 
     // Sort the displays.
     uasort($displays, function ($display1, $display2) {
-      if ($display1['position'] != $display2['position']) {
-        return $display1['position'] < $display2['position'] ? -1 : 1;
-      }
-      return 0;
+      return $display1['position'] <=> $display2['position'];
     });
 
     $form['displays'] = [