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
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
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ảng — Computes 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ố 8Mả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
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}
]
2Mảng để so sánh từ
arrays
array_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}
]
6Trả 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
3. Đó là, khi biểu diễn chuỗi là như nhau.
¶
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 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];
3J 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];
3DS2U tại hotmail dot com ¶
19 năm trước
Array
[
[0] => 1299.00
[1] => 1500.00
]
0Array
[
[0] => 1299.00
[1] => 1500.00
]
1Array
[
[0] => 1299.00
[1] => 1500.00
]
2Array
[
[0] => 1299.00
[1] => 1500.00
]
3Array
[
[0] => 1299.00
[1] => 1500.00
]
4Array
[
[0] => 1299.00
[1] => 1500.00
]
5Array
[
[0] => 1299.00
[1] => 1500.00
]
6Array
[
[0] => 1299.00
[1] => 1500.00
]
7Array
[
[0] => 1299.00
[1] => 1500.00
]
8Là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
]
9array_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[]
6Array_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];
3Sự mô tả ¶
17 năm trước
max[]
9
$array
0
$array
1
$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
3
$array
4
$array
5
$array
6
$array
7
$result = array[];
foreach [$data as $key => $subarr] {
if [count[array_unique[$subarr]] === 1] {
unset[$data[$key]];
} else {
$result[] = max[$subarr];
}
}
print_r[$result];
3DS2U tại hotmail dot com ¶
19 năm trước
$array
9
...$arrays
0
...$arrays
1
...$arrays
2
...$arrays
3
$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?
...$arrays
5
...$arrays
6
...$arrays
7
...$arrays
8
...$arrays
9Sử 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?
array
0
array
1
array
2
$result = array[];
foreach [$data as $key => $subarr] {
if [count[array_unique[$subarr]] === 1] {
unset[$data[$key]];
} else {
$result[] = max[$subarr];
}
}
print_r[$result];
3Bâ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
array
4
array
5
$result = array[];
foreach [$data as $key => $subarr] {
if [count[array_unique[$subarr]] === 1] {
unset[$data[$key]];
} else {
$result[] = max[$subarr];
}
}
print_r[$result];
3Là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?
array
7
Simon Riget tại paragi.dk ¶ ¶
16 năm trước
array
8
array
9
$result = array[];
foreach [$data as $key => $subarr] {
if [count[array_unique[$subarr]] === 1] {
unset[$data[$key]];
} else {
$result[] = max[$subarr];
}
}
print_r[$result];
3Javierchinapequeno tại Yahoo Dot es ¶ ¶
11 năm trước
arrays
1
Vojtech dot hordejcuk tại gmail dot com ¶ ¶
12 năm trước
arrays
2
arrays
3
arrays
4
arrays
5wrey75 tại gmail dot com ¶ ¶
7 năm trước
arrays
6
arrays
7
arrays
8
arrays
9
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];
3Coder 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];
3Coder 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}
]
4915 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