Skip to content

Commit

Permalink
PHP 7.x compatibility with is_assoc and is_list
Browse files Browse the repository at this point in the history
  • Loading branch information
borkweb committed Aug 26, 2023
1 parent 4029dbd commit bb28ce9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Arrays/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ public static function insert_before_key( $key, array $source_array, $insert ):
* @return bool
*/
public static function is_assoc( array $array ) {
return ! array_is_list( $array );
return ! static::is_list( $array );
}

/**
Expand All @@ -638,7 +638,18 @@ public static function is_assoc( array $array ) {
* @return bool
*/
public static function is_list( $array ) {
return array_is_list( $array );
if ( function_exists( 'array_is_list' ) ) {
return array_is_list( $array );
}

$i = 0;
foreach ( $array as $k => $v ) {
if ( $k !== $i++ ) {
return false;
}
}

return true;
}


Expand Down Expand Up @@ -1201,7 +1212,7 @@ public static function sort_recursive( $array, $options = SORT_REGULAR, $descend
}
}

if ( ! array_is_list( $array ) ) {
if ( ! static::is_list( $array ) ) {
$descending
? krsort( $array, $options )
: ksort( $array, $options );
Expand Down

0 comments on commit bb28ce9

Please sign in to comment.