Output of the "Sorting an array by descending numerical value" PHP snippet

Environment:

  • Strangebuzz Snippet VM: 2.2.1
  • PHP: 7.4

Code execution output:

Array
(
    [orange] => 3
    [lemon] => 1
    [banana] => 5
    [kiwi] => 11
    [apple] => 2
)
Array
(
    [kiwi] => 11
    [banana] => 5
    [orange] => 3
    [apple] => 2
    [lemon] => 1
)

 Back to the code  ≪ this.showUnitTest ? this.trans.hide_unit_test : this.trans.show_unit_test ≫  More on Stackoverflow   Read the doc  Run on 3v4l.org  Random snippet

<?php declare(strict_types=1);

namespace App\Tests\Controller\Snippets;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
 * @covers Snippet76Trait
 */
final class Snippet76Test extends KernelTestCase
{
    /**
     * @covers Snippet76Trait::snippet76
     */
    public function testSnippet76(): void
    {
        $myArray = [
            'orange' => 3,
            'lemon' => 1,
            'banana' => 5,
            'kiwi' => 11,
            'apple' => 2,
        ];
        arsort($myArray);
        $values = array_values($myArray);
        self::assertSame(11, $values[0]);
        self::assertSame(1, $values[count($myArray)-1]);
    }
}