{"id":105,"date":"2008-02-12T13:05:26","date_gmt":"2008-02-12T11:05:26","guid":{"rendered":"http:\/\/www.hermione.de\/blog\/?p=105"},"modified":"2008-05-13T14:51:50","modified_gmt":"2008-05-13T12:51:50","slug":"sort-php","status":"publish","type":"post","link":"http:\/\/blog.hermione.de\/?p=105","title":{"rendered":"sort [php]"},"content":{"rendered":"<h4>Sortieren von Arrays<\/h4>\n<p><strong>sort($array)<\/strong> sortiert ein Array<br \/>\n<strong>sort($array, SORT_STRING)<\/strong> Eintr\u00e4ge werden als Strings verglichen<br \/>\n<strong>sort($array, SORT_NUMERIC)<\/strong> Eintr\u00e4ge werden numerisch sortiert<br \/>\n<strong>rsort($array)<\/strong> Array wird in umgekehrter Reihenfolge sortiert<\/p>\n<h4>Assotiative Arrays<\/h4>\n<p><strong>ksort($array)<\/strong> sortiert Array nach keys<br \/>\n<strong>krsort($array)<\/strong> in umgekehrter Reihenfolge<br \/>\n<strong>asort($array)<\/strong> sortiert nach values ohne den Index kaputt zu machen<br \/>\n<strong>arsort($array)<\/strong> &#8230;<\/p>\n<h4>Mehrdimensionale Arrays<\/h4>\n<p><strong>usort<\/strong> sortiert ein Array anhand einer benutzerdefinierten Sortierfunktion<\/p>\n<table class=\"rosa\">\n<tbody>\n<tr>\n<td>\n<pre><code>&lt; ?php\r\n\r\n$artikel[0][\"titel\"] = \"Sort\";\r\n$artikel[1][\"titel\"] = \"PHP\";\r\n$artikel[0][\"hits\"] = 101;\r\n$artikel[1][\"hits\"] = 42;\r\n\r\nfunction cmp_titel($a, $b) {\r\n    return strcmp($a[\"titel\"], $b[\"titel\"]);\r\n}\r\n\r\nfunction cmp_hits($a,$b) {\r\n   if ($a[\"hits\"] == $b[\"hits\"]) {\r\n       \/\/ return 0;\r\n      return strcmp($a[\"titel\"], $b[\"titel\"]);\r\n   }\r\n   return ($a[\"hits\"] &gt; $b[\"hits\"]) ? +1 : -1;\r\n}\r\n\r\nusort($artikel, \"cmp_titel\");\r\nusort($artikel, \"cmp_hits\");\r\n?&gt;<\/code><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Sortieren von Arrays sort($array) sortiert ein Array sort($array, SORT_STRING) Eintr\u00e4ge werden als Strings verglichen sort($array, SORT_NUMERIC) Eintr\u00e4ge werden numerisch sortiert rsort($array) Array wird in umgekehrter Reihenfolge sortiert Assotiative Arrays ksort($array) sortiert Array nach keys krsort($array) in umgekehrter Reihenfolge asort($array) sortiert nach values ohne den Index kaputt zu machen arsort($array) &#8230; Mehrdimensionale Arrays usort sortiert ein [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/posts\/105"}],"collection":[{"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=105"}],"version-history":[{"count":0,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=\/wp\/v2\/posts\/105\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.hermione.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.hermione.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}