CoreFiles by mySites.guru
Arr.php47 lines, 1,189 bytes, from Joomla_4.3.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 4.3.0-alpha1
md5
abf98f00969c639cf04e78ad01f1c099
sha1
16a52d69021c6dabfb3b1abf1c884fc1ef7be31a
sha256
f4a45c99c24f6381e55a1b1778d1334d87d4a44909923aac65c24fac8f83b4a3
<?php

declare(strict_types=1);

namespace Jfcherng\Diff\Utility;

final class Arr
{
    /**
     * Get a partial array slice with start/end indexes.
     *
     * @param array    $array the array
     * @param int      $start the starting index (negative = count from backward)
     * @param null|int $end   the ending index (negative = count from backward)
     *                        if is null, it returns a slice from $start to the end
     *
     * @return array array of all of the lines between the specified range
     */
    public static function getPartialByIndex(array $array, int $start = 0, ?int $end = null): array
    {
        $count = \count($array);

        // make $end set
        $end = $end ?? $count;

        // make $start non-negative
        if ($start < 0) {
            $start += $count;

            if ($start < 0) {
                $start = 0;
            }
        }

        // make $end non-negative
        if ($end < 0) {
            $end += $count;

            if ($end < 0) {
                $end = 0;
            }
        }

        // make the length non-negative
        return \array_slice($array, $start, \max(0, $end - $start));
    }
}

The same content is in 2 releases, Joomla 4.3.0-alpha1 to 4.3.0-alpha2. See them all, or every version of this file.