sort(): Sortieren Sie einfach die Elemente eines Arrays von niedrig nach hoch. Diese Funktion kann entweder numerisch oder alphabetisch angeordnet werden.
<code>Listing A <span><?php</span><span>$data</span> = <span>array</span>(<span>5</span>,<span>8</span>,<span>1</span>,<span>7</span>,<span>2</span>); sort(<span>$data</span>); print_r(<span>$data</span>); <span>?></span>输出结果如下所示: <span>Array</span> ([<span>0</span>] => <span>1</span>[<span>1</span>] => <span>2</span>[<span>2</span>] => <span>5</span>[<span>3</span>] => <span>7</span>[<span>4</span>] => <span>8</span>)</code>
rsort(): Sortiert die Array-Elemente von hoch nach niedrig, entweder numerisch oder alphabetisch.
<code><span><?php</span><span>$data</span> = <span>array</span>(<span>5</span>,<span>8</span>,<span>1</span>,<span>7</span>,<span>2</span>);rsort(<span>$data</span>); print_r(<span>$data</span>); <span>?></span>它的输出结果如下: <span>Array</span> ([<span>0</span>] => <span>8</span>[<span>1</span>] => <span>7</span>[<span>2</span>] => <span>5</span>[<span>3</span>] => <span>2</span>[<span>4</span>] => <span>1</span>)</code>
ksort(): Eine Funktion, die nach Schlüsselwörtern sortiert und gleichzeitig die Relevanz von Schlüsselwörtern während des Sortiervorgangs beibehält.
<code><span><?php</span><span>$data</span> = <span>array</span>(<span>"US"</span> => <span>"United States"</span>, <span>"IN"</span> => <span>"India"</span>, <span>"DE"</span> => <span>"Germany"</span>, <span>"ES"</span> => <span>"Spain"</span>); ksort(<span>$data</span>); print_r(<span>$data</span>); <span>?></span>它的输出结果如下: <span>Array</span> ([DE] => Germany [ES] => Spain [IN] => India [US] => United States )</span></code>
krsort(): Sortiert das Array nach Schlüsselwörtern.
<code><span><?php</span><span>$data</span> = <span>array</span>(<span>"US"</span> => <span>"United States"</span>, <span>"IN"</span> => <span>"India"</span>, <span>"DE"</span> => <span>"Germany"</span>, <span>"ES"</span> => <span>"Spain"</span>); krsort(<span>$data</span>); print_r(<span>$data</span>); <span>?></span>它的输出结果如下: <span>Array</span> ([US] => United States [IN] => India [ES] => Spain [DE] => Germany )</span></code>
asort(): Wertsortierung statt Schlüsselwortsortierung verwenden. Bitte beachten Sie, dass die Beziehung zwischen Schlüsselwörtern und Werten immer erhalten bleibt.
<code><span><?php</span><span>$data</span> = <span>array</span>(<span>"US"</span> => <span>"United States"</span>, <span>"IN"</span> => <span>"India"</span>, <span>"DE"</span> => <span>"Germany"</span>, <span>"ES"</span> => <span>"Spain"</span>); asort(<span>$data</span>); print_r(<span>$data</span>); <span>?></span>它的输出结果如下: <span>Array</span> ([DE] => Germany [IN] => India [ES] => Spain [US] => United States )</span></code>
arsort(): Sortiert in alphabetischer Reihenfolge nach Wert.
<code><span><?php</span><span>$data</span> = <span>array</span>(<span>"US"</span> => <span>"United States"</span>, <span>"IN"</span> => <span>"India"</span>, <span>"DE"</span> => <span>"Germany"</span>, <span>"ES"</span> => <span>"Spain"</span>); arsort(<span>$data</span>); print_r(<span>$data</span>); <span>?></span><span>Array</span> ([US] => United States [ES] => Spain [IN] => India [DE] => Germany )</span></code>
Das Obige stellt die Sortierfunktion von PHP vor, einschließlich Aspekten des Inhalts. Ich hoffe, dass es für Freunde hilfreich ist, die sich für PHP-Tutorials interessieren.