Hướng dẫn how to compare values in array in php - cách so sánh các giá trị trong mảng trong php

0

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi có cấu trúc mảng sau. Tôi muốn nhận được giá trị tối đa trong mảng và nếu các giá trị trong mảng giống nhau để hủy bỏ mảng này.

   Array(

        [499670] => Array
            (
                [499670] => 1299.00
                [503410] => 1299.00
                [528333] => 1299.00
                [645862] => 0.00
            )

        [499671] => Array
            (
                [499671] => 1149.00
                [503408] => 1149.00
                [528329] => 1500.00
                [645858] => 0.00
            )

        [499672] => Array
            (
                [499672] => 0.00
                [503406] => 0.00
                [528324] => 0.00
                [645850] => 0.00
            )
)

Tôi muốn nhận được kết quả sau

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)

Đã hỏi ngày 20 tháng 3 năm 2014 lúc 16:34Mar 20, 2014 at 16:34

Hướng dẫn how to compare values in array in php - cách so sánh các giá trị trong mảng trong php

2

Lặp lại thông qua mảng của bạn, sử dụng array_unique() để kiểm tra xem tất cả các giá trị có giống nhau không. Nếu không, hãy tìm giá trị tối đa bằng cách sử dụng max():

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);

Output:

Array
(
    [0] => 1299.00
    [1] => 1500.00
)

Thử nghiệm

Đã trả lời ngày 20 tháng 3 năm 2014 lúc 16:37Mar 20, 2014 at 16:37

Hướng dẫn how to compare values in array in php - cách so sánh các giá trị trong mảng trong php

Amal Muraliamal MuraliAmal Murali

74K18 Huy hiệu vàng126 Huy hiệu bạc145 Huy hiệu Đồng18 gold badges126 silver badges145 bronze badges

2

(Php 4> = 4.0.1, Php 5, Php 7, Php 8)

mảng_diff - tính toán sự khác biệt của mảngComputes the difference of arrays

Sự mô tả

mảng_diff (mảng $array, mảng ...$arrays): mảng(array $array, array ...$arrays): array

Thông số

________số 8

Mảng để so sánh từ

arrays

Mảng để so sánh với

Trả về giá trị

Trả về một mảng chứa tất cả các mục từ array không có trong bất kỳ mảng nào khác. Chìa khóa trong mảng array được bảo quản.array containing all the entries from array that are not present in any of the other arrays. Keys in the array array are preserved.

Thay đổi

Phiên bảnSự mô tả
8.0.0 mảng_diff (mảng $array, mảng ...$arrays): mảng

Thông số

________số 8array_diff() example

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
2

Mảng để so sánh từ

arraysarray_diff() example with non-matching types

Mảng để so sánh với

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
4

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
5

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
6

Trả về giá trịarray_udiff().

Trả về một mảng chứa tất cả các mục từ array không có trong bất kỳ mảng nào khác. Chìa khóa trong mảng array được bảo quản.

Thay đổi:

Phiên bản

Hàm này bây giờ có thể được gọi chỉ với một tham số. Trước đây, ít nhất hai tham số đã được yêu cầu.

  • Ví dụ
  • Ví dụ #1 Array_diff () ví dụ
  • Nhiều lần xuất hiện trong $ Array1 đều được xử lý theo cùng một cách. Điều này sẽ xuất hiện:
  • Ví dụ #2 Array_diff () Ví dụ với các loại không phù hợp

Hai yếu tố được coi là bằng nhau khi và chỉ khi

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
3. Đó là, khi biểu diễn chuỗi là như nhau.

15 năm trước

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
8

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
9

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
0

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
1

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
2

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Ẩn danh ¶

16 năm trước

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
4

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
5

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

J dot j dot d dot mol at ewi dot tudelft dot nl ¶

17 năm trước

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
7

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
8

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

DS2U tại hotmail dot com

19 năm trước

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
0

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
1

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
2

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
3

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
4

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
5

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
6

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
7

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
8

Làm thế nào để bạn so sánh các giá trị trong một mảng?

Sử dụng các phương thức mảng.equals (Array1, Array2) - Phương thức này lặp lại trên từng giá trị của một mảng và so sánh bằng phương thức bằng. Sử dụng mảng. Phương thức Deepequals (Array1, Array2) - Phương thức này lặp lại trên từng giá trị của một mảng và so sánh sâu bằng bất kỳ phương thức nào được ghi đè.

Array
(
    [0] => 1299.00
    [1] => 1500.00
)
9

array_unique()0

array_unique()1

array_unique()2

Làm thế nào để bạn kiểm tra xem hai giá trị trong một mảng bằng PHP?

Bây giờ, để kiểm tra xem hai mảng có bằng hay không, một lần lặp có thể được thực hiện trên các mảng và kiểm tra xem mỗi chỉ mục có giá trị liên quan đến chỉ mục trong cả hai mảng có giống nhau hay không. PHP có toán tử mảng sẵn có (===) để kiểm tra giống nhau nhưng ở đây, thứ tự các phần tử mảng không quan trọng.

array_unique()3

array_unique()4

array_unique()5

array_unique()6

Array_Keys () được sử dụng trong PHP là gì?

Array_Keys () là một hàm tích hợp trong PHP và được sử dụng để trả về tất cả các khóa và mảng hoặc tập hợp con của các khóa. Tham số: Hàm lấy ba tham số trong đó một tham số là bắt buộc và hai tham số khác là tùy chọn.

array_unique()7

Làm thế nào để bạn so sánh các số trong hai mảng?

phương thức bằng (). Lớp mảng Java cung cấp phương thức bằng () để so sánh hai mảng. Nó lặp lại trên mỗi giá trị của một mảng và so sánh các phần tử bằng phương thức bằng ().

array_unique()8

array_unique()9

max()0

max()1

(Php 4> = 4.0.1, Php 5, Php 7, Php 8)

mảng_diff - tính toán sự khác biệt của mảng

max()2

max()3

max()4

max()5

max()6

max()7

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Sự mô tả

17 năm trước

max()9

$array0

$array1

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Ẩn danh ¶

7 năm trước

$array3

$array4

$array5

$array6

$array7

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

DS2U tại hotmail dot com

19 năm trước

$array9

...$arrays0

...$arrays1

...$arrays2

...$arrays3

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Ẩn danh ¶

Làm thế nào để bạn so sánh các giá trị trong một mảng?

...$arrays5

...$arrays6

...$arrays7

...$arrays8

...$arrays9

Sử dụng các phương thức mảng.equals (Array1, Array2) - Phương thức này lặp lại trên từng giá trị của một mảng và so sánh bằng phương thức bằng. Sử dụng mảng. Phương thức Deepequals (Array1, Array2) - Phương thức này lặp lại trên từng giá trị của một mảng và so sánh sâu bằng bất kỳ phương thức nào được ghi đè.

Làm thế nào để bạn kiểm tra xem hai giá trị trong một mảng bằng PHP?

array0

array1

array2

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Bây giờ, để kiểm tra xem hai mảng có bằng hay không, một lần lặp có thể được thực hiện trên các mảng và kiểm tra xem mỗi chỉ mục có giá trị liên quan đến chỉ mục trong cả hai mảng có giống nhau hay không. PHP có toán tử mảng sẵn có (===) để kiểm tra giống nhau nhưng ở đây, thứ tự các phần tử mảng không quan trọng.

19 năm trước

array4

array5

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Làm thế nào để bạn so sánh các giá trị trong một mảng?

Làm thế nào để bạn kiểm tra xem hai giá trị trong một mảng bằng PHP?

array7

Simon Riget tại paragi.dk ¶

16 năm trước

array8

array9

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Javierchinapequeno tại Yahoo Dot es ¶

11 năm trước

arrays1

Vojtech dot hordejcuk tại gmail dot com ¶

12 năm trước

arrays2

arrays3

arrays4

arrays5

wrey75 tại gmail dot com ¶

7 năm trước

arrays6

arrays7

arrays8

arrays9

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
00

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Ẩn danh ¶

13 năm trước

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
02

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
03

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
04

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
05

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
06

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
07

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
08

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
09

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
10

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
11

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
12

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
13

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
14

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
15

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
16

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
17

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
18

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
19

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
20

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
21

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
22

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
23

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
24

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
25

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
26

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
27

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
28

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
29

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
30

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
31

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Coder Viking ¶

16 năm trước

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
33

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
34

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
35

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
36

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Ẩn danh ¶

7 năm trước

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
38

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
39

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
40

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Ẩn danh ¶

13 năm trước

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
42

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
43

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
44

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Coder Viking ¶

Gilthans tại Nogmailspam dot com ¶

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
46

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
47

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
48

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
49

15 năm trước

J dot j dot d dot mol at ewi dot tudelft dot nl ¶

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
50

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
51

   Array(

                [499670] => 1299.00 >>> one of values in first array
                [528329] => 1500.00 >>> max value in second array
                {third array was removed, because all values are same}

)
52

$result = array();

foreach ($data as $key => $subarr) {
    if (count(array_unique($subarr)) === 1) {
        unset($data[$key]);
    } else {
        $result[] = max($subarr);
    }
}

print_r($result);
3

Làm thế nào để bạn so sánh các giá trị trong một mảng?

Sử dụng các phương thức mảng.equals (Array1, Array2) - Phương thức này lặp lại trên từng giá trị của một mảng và so sánh bằng phương thức bằng. Sử dụng mảng. Phương thức Deepequals (Array1, Array2) - Phương thức này lặp lại trên từng giá trị của một mảng và so sánh sâu bằng bất kỳ phương thức nào được ghi đè. equals(array1, array2) methods − This method iterates over each value of an array and compare using equals method. Using Arrays. deepEquals(array1, array2) methods − This method iterates over each value of an array and deep compare using any overridden equals method.

Làm thế nào để bạn kiểm tra xem hai giá trị trong một mảng bằng PHP?

Bây giờ, để kiểm tra xem hai mảng có bằng hay không, một lần lặp có thể được thực hiện trên các mảng và kiểm tra xem mỗi chỉ mục có giá trị liên quan đến chỉ mục trong cả hai mảng có giống nhau hay không. PHP có toán tử mảng sẵn có (===) để kiểm tra giống nhau nhưng ở đây, thứ tự các phần tử mảng không quan trọng.an iteration can be done over the arrays and check whether for each index the value associated with the index in both the arrays is the same or not. PHP has an inbuilt array operator( === ) to check the same but here the order of array elements is not important.

Array_Keys () được sử dụng trong PHP là gì?

Array_Keys () là một hàm tích hợp trong PHP và được sử dụng để trả về tất cả các khóa và mảng hoặc tập hợp con của các khóa.Tham số: Hàm lấy ba tham số trong đó một tham số là bắt buộc và hai tham số khác là tùy chọn.to return either all the keys of and array or the subset of the keys. Parameters: The function takes three parameters out of which one is mandatory and other two are optional.

Làm thế nào để bạn so sánh các số trong hai mảng?

phương thức bằng ().Lớp mảng Java cung cấp phương thức Equals () để so sánh hai mảng.Nó lặp lại trên mỗi giá trị của một mảng và so sánh các phần tử bằng phương thức bằng ().. Java Arrays class provides the equals() method to compare two arrays. It iterates over each value of an array and compares the elements using the equals() method.