{"id":394,"date":"2022-10-27T09:56:37","date_gmt":"2022-10-27T09:56:37","guid":{"rendered":"https:\/\/www.devopstrainer.in\/blog\/?p=394"},"modified":"2022-10-28T07:04:35","modified_gmt":"2022-10-28T07:04:35","slug":"list-of-functions-available-to-sort-an-php-array-explain-with-example","status":"publish","type":"post","link":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/","title":{"rendered":"List of functions available to sort an PHP array? Explain with example?"},"content":{"rendered":"\n<p>In PHP, we have six functions for sorting array:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><mark style=\"background-color:#7bdcb5\" class=\"has-inline-color\">sort()= it sort an array in ascending order<\/mark><\/li><li><mark style=\"background-color:#7bdcb5\" class=\"has-inline-color\">rsort()= it sort an array in descending order<\/mark><\/li><li><mark style=\"background-color:#7bdcb5\" class=\"has-inline-color\">asort()= it sort an array in ascending order, according to the value<\/mark><\/li><li><mark style=\"background-color:#7bdcb5\" class=\"has-inline-color\">ksort()= it sort an array in ascending order, according to the key<\/mark><\/li><li><mark style=\"background-color:#7bdcb5\" class=\"has-inline-color\">arsort()= it sort an array in descending order, according to the value<\/mark><\/li><li><mark style=\"background-color:#7bdcb5\" class=\"has-inline-color\">krsort()= it sort an array in descending order, according to the key<\/mark><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\t\t<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-cyan-bluish-gray-color\">$num = array(21,23,34,45,1,4,5,);\n\t\t sort($num);\n\n\t   $numlength = count($num);\n\t\t for($t = 0; $t &lt; $numlength; $t++) \n\t\t {\n\t\t    echo $num&#91;$t];\n\t\t   \n\t\t }\n\t\t<\/mark> \n\t\t \n\t\t echo \"&lt;br&gt;&lt;br&gt;\";\n\t\t echo \"&lt;br&gt;\";\n\t\t \n\t\t \n\t\t \n\t\t <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">$num = array(21,23,34,45,1,4,5,);\n\t\t rsort($num);\n\n\t   $numlength = count($num);\n\t\t for($t = 0; $t &lt; $numlength; $t++) \n\t\t {\n\t\t    echo $num&#91;$t];\n\t\t\techo \"&lt;br&gt;\";\n\t\t   \n\t\t }\n\t\t <\/mark>\n\t\t echo \"&lt;br&gt;\";\n\t\t echo \"&lt;br&gt;\";\n\t\t \n\t\t <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">$team = array(\"shivam\"=&gt;\"20\", \"ravi\"=&gt;\"22\", \"abhi\"=&gt;\"24\");\n         asort($team);\n\n         foreach($team as $value =&gt; $value_v) \n\t\t {\n         echo \"Key=\" . $value . \", Value=\" . $value_v;\n         echo \"&lt;br&gt;\";\n         }<\/mark>\n\n          echo \"&lt;br&gt;\";\n\t\t echo \"&lt;br&gt;\";\n\t\t \n\t\t <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">$team = array(\"shivam\"=&gt;\"20\", \"ravi\"=&gt;\"22\", \"abhi\"=&gt;\"24\");\n         ksort($team);\n\n         foreach($team as $value =&gt; $value_v) \n\t\t {\n         echo \"Key=\" . $value . \", Value=\" . $value_v;\n         echo \"&lt;br&gt;\";\n\t\t }\n\t\t <\/mark>\n\t\t \n\t\t echo \"&lt;br&gt;\";\n\t\t echo \"&lt;br&gt;\";\n\t\t \n\t\t<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\"> $team = array(\"shivam\"=&gt;\"20\", \"ravi\"=&gt;\"22\", \"abhi\"=&gt;\"24\");\n         arsort($team);\n\n         foreach($team as $value =&gt; $value_v) \n\t\t {\n         echo \"Key=\" . $value . \", Value=\" . $value_v;\n         echo \"&lt;br&gt;\";\n\t\t }\n<\/mark>\n\t\t \n\t\t \n\t\t \n\t\t <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-light-green-cyan-color\">echo \"&lt;br&gt;\";\n\t\t echo \"&lt;br&gt;\";\n\t\t \n\t\t $team = array(\"shivam\"=&gt;\"20\", \"ravi\"=&gt;\"22\", \"abhi\"=&gt;\"24\");\n         krsort($team);\n\n         foreach($team as $value =&gt; $value_v) \n\t\t {\n         echo \"Key=\" . $value . \", Value=\" . $value_v;\n         echo \"&lt;br&gt;\";\n\t\t }\n\n<\/mark>\n?&gt;\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">output<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-cyan-bluish-gray-color\">14521233445<\/mark>\n\n\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">45\n34\n23\n21\n5\n4\n1<\/mark>\n\n\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">Key=shivam, Value=20\nKey=ravi, Value=22\nKey=abhi, Value=24<\/mark>\n\n\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Key=abhi, Value=24\nKey=ravi, Value=22\nKey=shivam, Value=20<\/mark>\n\n\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">Key=abhi, Value=24\nKey=ravi, Value=22\nKey=shivam, Value=20\n<\/mark>\n\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-light-green-cyan-color\">Key=shivam, Value=20\nKey=ravi, Value=22\nKey=abhi, Value=24\n<\/mark><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In PHP, we have six functions for sorting array: sort()= it sort an array in ascending order rsort()= it sort an array in descending order asort()= it sort an array&hellip;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-394","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>List of functions available to sort an PHP array? Explain with example? - DevOps | SRE | DevSecOps<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"List of functions available to sort an PHP array? Explain with example? - DevOps | SRE | DevSecOps\" \/>\n<meta property=\"og:description\" content=\"In PHP, we have six functions for sorting array: sort()= it sort an array in ascending order rsort()= it sort an array in descending order asort()= it sort an array&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps | SRE | DevSecOps\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-27T09:56:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-28T07:04:35+00:00\" \/>\n<meta name=\"author\" content=\"shivam\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"shivam\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/\"},\"author\":{\"name\":\"shivam\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53\"},\"headline\":\"List of functions available to sort an PHP array? Explain with example?\",\"datePublished\":\"2022-10-27T09:56:37+00:00\",\"dateModified\":\"2022-10-28T07:04:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/\"},\"wordCount\":87,\"commentCount\":0,\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/\",\"url\":\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/\",\"name\":\"List of functions available to sort an PHP array? Explain with example? - DevOps | SRE | DevSecOps\",\"isPartOf\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#website\"},\"datePublished\":\"2022-10-27T09:56:37+00:00\",\"dateModified\":\"2022-10-28T07:04:35+00:00\",\"author\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.devopstrainer.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"List of functions available to sort an PHP array? Explain with example?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#website\",\"url\":\"https:\/\/www.devopstrainer.in\/blog\/\",\"name\":\"DevOps | SRE | DevSecOps\",\"description\":\"Automation means Cost, Quality, Time\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.devopstrainer.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53\",\"name\":\"shivam\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g\",\"caption\":\"shivam\"},\"url\":\"https:\/\/www.devopstrainer.in\/blog\/author\/shivam\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"List of functions available to sort an PHP array? Explain with example? - DevOps | SRE | DevSecOps","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/","og_locale":"en_US","og_type":"article","og_title":"List of functions available to sort an PHP array? Explain with example? - DevOps | SRE | DevSecOps","og_description":"In PHP, we have six functions for sorting array: sort()= it sort an array in ascending order rsort()= it sort an array in descending order asort()= it sort an array&hellip;","og_url":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/","og_site_name":"DevOps | SRE | DevSecOps","article_published_time":"2022-10-27T09:56:37+00:00","article_modified_time":"2022-10-28T07:04:35+00:00","author":"shivam","twitter_card":"summary_large_image","twitter_misc":{"Written by":"shivam","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/#article","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/"},"author":{"name":"shivam","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"headline":"List of functions available to sort an PHP array? Explain with example?","datePublished":"2022-10-27T09:56:37+00:00","dateModified":"2022-10-28T07:04:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/"},"wordCount":87,"commentCount":0,"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/","url":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/","name":"List of functions available to sort an PHP array? Explain with example? - DevOps | SRE | DevSecOps","isPartOf":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#website"},"datePublished":"2022-10-27T09:56:37+00:00","dateModified":"2022-10-28T07:04:35+00:00","author":{"@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53"},"breadcrumb":{"@id":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.devopstrainer.in\/blog\/list-of-functions-available-to-sort-an-php-array-explain-with-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.devopstrainer.in\/blog\/"},{"@type":"ListItem","position":2,"name":"List of functions available to sort an PHP array? Explain with example?"}]},{"@type":"WebSite","@id":"https:\/\/www.devopstrainer.in\/blog\/#website","url":"https:\/\/www.devopstrainer.in\/blog\/","name":"DevOps | SRE | DevSecOps","description":"Automation means Cost, Quality, Time","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.devopstrainer.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/0c8259479972d3d18994f88df3dc8d53","name":"shivam","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.devopstrainer.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/be603b13110d1423e9358d9f4b8901acd56c4239bca1b26b0225d217c2a2f1eb?s=96&d=mm&r=g","caption":"shivam"},"url":"https:\/\/www.devopstrainer.in\/blog\/author\/shivam\/"}]}},"_links":{"self":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/comments?post=394"}],"version-history":[{"count":3,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/394\/revisions"}],"predecessor-version":[{"id":454,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/posts\/394\/revisions\/454"}],"wp:attachment":[{"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/media?parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/categories?post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopstrainer.in\/blog\/wp-json\/wp\/v2\/tags?post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}