CoreFiles by mySites.guru
Arr.php65 lines, 1,601 bytes, from Joomla_4.4.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 4.4.0-alpha1
md5
093910c1c5d2c9656a90a74242e1f1c4
sha1
c97976e3b74f54d36246ec85093882d35333eff1
sha256
db106a2bf7a4c31ca9cdb9ab30439242cd45c492e6325a65ae6f9f0390c4351f
<?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));
    }

    /**
     * Determines whether the array is associative.
     *
     * @param array $arr the array
     *
     * @return bool `true` if the array is associative, `false` otherwise
     */
    public static function isAssociative($arr): bool
    {
        foreach ($arr as $key => $value) {
            if (\is_string($key)) {
                return true;
            }
        }

        return false;
    }
}

The same content is in 54 releases, Joomla 4.3.0-alpha3 to 4.4.14. See them all, or every version of this file.