У меня есть два массива:
<?php
$arr1 = ["","2nd Level","11' Ceilings","1016 SF","1168SF","1186-1204SF","11ft Ceilings","1211-1226SF","14 Square Footage","15 Square Footage","16 Square Footage","17 Square Footage","18 Square Footage","19 Square Footage","20 Square Footage","21 Square Footage","2nd","3rd","4th","538-541SF","543-564SF","547-557SF","5th","614-619SF","629-639SF","6th","701-724SF","7th Fl PH1A","8th Street View","905-1046SF","Additional Closets","Alley View","Alley View 2","Alley\/Wall View 65 Stack","Bradley","City View","Corner Unit","Courtyard View","Dbl Balcony","Double Windows","Eisen 1","Eisen 2","Eisen 3","Eisen 4","End Unit","Goodwin","Grand Ave View","Int Corner 2","Interior Corner","Large Storage","Lg. Balcony","Loss Leader","Loss Leader2","Loss Leader3","Loss Leader4","Nielson 1","Nielson 2","Nielson 3","Nielson 4","Nielson 5","Nielson 6","Olive Street View","Partial Courtyard View","Partial Pool View","Patio","Ph1a","Ph1b","Ph2","Ph3","Pol. Concrete","Pool View","Regular Balcony","Rent","Sm. Balcony","Small Storage","Top Floor","View 4","View 5","Walk-in Closet","Walker","murphy bed"];
$arr2 = array (
'1st Floor' => 375,
'2nd Floor' => 375,
'3rd Floor' => 375,
'4th Floor' => 375,
'5th Floor' => 375,
'Fireplace' => 384,
'RPRenovation' => 380,
'Renovated' => 380,
'Rent' => 381,
'Test' => 383,
'FEAT-ADA' => 368,
'FEAT-GAR 1C' => 384,
'FEAT-W/D' => 384,
'FEAT-YARD' => 384,
'FL-LC--1B' => 375,
'FL-LC--2B' => 375,
'FL-LC-All-1B' => 375,
'FL-LC-All-2B' => 375,
'FL-P1--1B' => 375,
'FL-P1--2B' => 375,
'LOC-NEG' => 379,
'LOC-OTHER' => 379,
'LVL-1ST-1B' => 375,
'LVL-1ST-2B' => 375,
'LVL-TOP-1B' => 375,
'LVL-TOP-2B' => 375,
'R-LC-DMD-1B' => 375,
'R-LC-DMD-2B' => 379,
'R-LC-GLD-1B' => 379,
'R-LC-GLD-2B' => 379,
'R-LC-PLT-1B' => 379,
'R-LC-PLT-2B' => 379,
'base rent adj' => 381,
'Balcony' => 370,
'1/2 Bath' => 371,
'2018 Bathroom Upgrade' => 371,
'2018 Kitchen Upgrade' => 378,
'2018 Laminate Countertops' => 377,
'2018 Stainless Steel Appliance' => 378,
'2018 Subway Tile' => 377,
'2018 Vinyl Plank Flooring' => 377,
'Accessible Unit' => 368,
'Bonus Room' => 382,
'Bottom Floor' => 375,
'Building B' => 379,
'Building D' => 379,
'Building E' => 379,
'Bump Out' => 384,
'Cinderblock Walls' => 384,
'Corner unit' => 374,
'Electric Included With Rent' => 381,
'Extra Storage' => 373,
'French Doors' => 384,
'Hardwood Floors' => 377,
'Laundry Room' => 379,
'Non-Operable Windows' => 387,
'Platform with Storage' => 373,
'Square Feet: 1000 (1BD)' => 382,
'Square Feet: 1008 (1BD)' => 382,
'Square Feet: 1030 (1BD)' => 382,
'Square Feet: 1108 (2BD)' => 382,
'Square Feet: 1110 (2BD)' => 382,
'Square Feet: 1121 (2BD)' => 382,
'Square Feet: 1123 (1BD)' => 382,
'Square Feet: 1130 (2BD)' => 382,
'Square Feet: 1170 (2BD)' => 382,
'Square Feet: 1175 (2BD) Base' => 382,
'Square Feet: 1220 (2BD)' => 382,
'Square Feet: 1237 (2BD)' => 382,
'Square Feet: 1280 (2BD)' => 382,
'Square Feet: 1309 (2BD)' => 382,
'Square Feet: 1342 (2BD)' => 382,
'Square Feet: 580 (1BD)' => 382,
'Square Feet: 583 (1BD)' => 382,
'Square Feet: 691 (1BD)' => 382,
'Square Feet: 696 (1BD)' => 382,
'Square Feet: 740 (1BD)' => 382,
'Square Feet: 748 (1BD)' => 382,
'Square Feet: 789 (1BD)' => 382,
'Square Feet: 792 (1BD)' => 382,
'Square Feet: 805 (1BD) Base' => 382,
'Square Feet: 847 (1BD)' => 382,
'Square Feet: 848 (2BD)' => 382,
'Square Feet: 880 (1BD)' => 382,
'Square Feet: 912 (1BD)' => 382,
'Square Feet: 974 (1BD)' => 382,
'Square Feet: 987 (1BD)' => 382,
'Stainless steel appliances' => 378,
'Standard Townhome' => 383,
'Top Floor' => 375,
'View - Motorcycle Parking' => 386,
'View - Parking' => 386,
'View - Partial River' => 386,
'View - Railroad Tracks' => 386,
'View - River' => 386,
'View - Service Area' => 386,
'Windows Do Not Open' => 387,
'Ada' => 368,
'accessible' => 368,
'handicap' => 368,
'Affordable' => 369,
'BMR' => 369,
'Bond' => 369,
'HAP' => 369,
'balconies' => 370,
'Patio' => 370,
'Terrace' => 370,
'Lanai' => 370,
'Bathroom' => 371,
'bathrooms' => 371,
'Shower' => 371,
'showers' => 371,
'Vanity' => 371,
'sink' => 371,
'Ceiling' => 372,
'ceilings' => 372,
'vaulted' => 372,
'Storage' => 373,
'Closet' => 373,
'closets' => 373,
'Walk-in' => 373,
'Linen' => 373,
'Corner' => 374,
'corners' => 374,
'Level' => 375,
'levels' => 375,
'1st' => 375,
'2nd' => 375,
'3rd' => 375,
'4th' => 375,
'5th' => 375,
'6th' => 375,
'7th' => 375,
'8th' => 375,
'9th' => 375,
'10th' => 375,
'11th' => 375,
'12th' => 375,
'13th' => 375,
'14th' => 375,
'15th' => 375,
'16th' => 375,
'17th' => 375,
'18th' => 375,
'19th' => 375,
'20th' => 375,
'Layout' => 376,
'layouts' => 376,
'floor plan' => 376,
'floorplan' => 376,
'Finish' => 377,
'finishes' => 377,
'Flooring' => 377,
'Wood' => 377,
'Plank' => 377,
'Vinyl' => 377,
'Kitchen' => 378,
'kitchens' => 378,
'Stainless' => 378,
'Appliance' => 378,
'appliances' => 378,
'Location' => 379,
'locations' => 379,
'End' => 379,
'Reno' => 380,
'renovation' => 380,
'renovations' => 380,
'Platinum' => 380,
'Silver' => 380,
'Gold' => 380,
'Upgrade' => 380,
'upgrades' => 380,
'Rents' => 381,
'Discount' => 381,
'Loss Leader' => 381,
'SF' => 382,
'sqft' => 382,
'sq ft' => 382,
'square feet' => 382,
'square foot' => 382,
'sq feet' => 382,
'square footage' => 382,
'Feature' => 384,
'features' => 384,
'W/D' => 384,
'WD' => 384,
'Washer' => 384,
'Dryer' => 384,
'Garage' => 384,
'Garages' => 384,
'Driveway' => 384,
'view' => 386,
'views' => 386,
'Window' => 387,
'windows' => 387,
);
Требования:
Условия проверки
1) Проверьте, есть ли какое-либо значение $arr1
в ключе $arr2
. 2) Если значение не совпадает точно, нам нужно отделить слова от значения $arr1
и проверить, совпадают ли все слова и имеют ли они одинаковое значение.
, например,
- проверить, совпадает ли
2nd level
с любым ключом в $arr2
. - , если
2nd level
не оштрафовать совпадения, разделите 2nd level
на 2nd
и level
. Если оба значения 2nd
и level
соответствуют ключу с одинаковым значением.
В этом случае значения 2nd
и level
имеют значение 375
, это означает, что это следует считать совпадением. В случае, если 2nd
имел 375
и level
имел 376
, это не будет совпадением.
Если найдено:
Выше я упомянул два способа, которые можно было бы рассмотреть в случае совпадения, и, если совпадение найдено, результат записывается в новый массив $result
с индексом $arr1
.
Например: если $res[0]
не найдено совпадения, то $res[0] = ''
. Аналогично, `$ res [1] = '375' и т. Д.
Например: массив $res
может иметь вид:
$res = array (
0 => '',
1 => '375',
2 => '',
3 => '',
4 => '',
5 => '',
6 => '',
7 => '',
8 => '',
9 => '',
10 => '',
11 => '',
12 => '',
13 => '',
14 => '',
15 => '',
16 => 375,
17 => 375,
18 => 375,
19 => '',
20 => '',
21 => '',
22 => 375,
23 => '',
24 => '',
25 => 375,
26 => '',
27 => '',
28 => '',
29 => '',
30 => '',
31 => '',
32 => '',
33 => '',
34 => '',
35 => '',
36 => 374,
37 => '',
38 => '',
39 => '',
40 => '',
41 => '',
42 => '',
43 => '',
44 => '',
45 => '',
46 => '',
47 => '',
48 => '',
49 => '',
50 => '',
51 => 381,
52 => '',
53 => '',
54 => '',
55 => '',
56 => '',
57 => '',
58 => '',
59 => '',
60 => '',
61 => '',
62 => '',
63 => '',
64 => 370,
65 => '',
66 => '',
67 => '',
68 => '',
69 => '',
70 => '',
71 => '',
72 => 381,
73 => '',
74 => '',
75 => 375,
76 => '',
77 => '',
78 => '',
79 => '',
80 => '',
)
note:
$res
массив может отличаться от показанного, поскольку это было только предположение, но формат должен быть таким. Кроме того, мы можем игнорировать регистр символов.
#
По сути, для первой проверки я мог бы сделать это, зацикливаясь на два массива foreach как:
$res = array();
foreach($arr1 as $ak => $av){
$match = false;
foreach($arr2 as $k => $v){
if(!empty($av) && !empty($k)){
if (preg_match("`\b" . preg_quote($av) . "\b`i", $k)) {
array_push($res, $ar);
$match= true;
break;
}
}
}
}
if(!$match) {
array_push($res, '');
}
Эта работа для проверки условия 1, но нужно добавить для проверки 2, однако я не уверен, что это эффективный способ, так как в будущем этот массив может быть большим, особенно $arr2
.
Обновление:
Приносим извинения за неудобства, здесь точное совпадение означает, что значение из $arr1
должно быть поднабором ключа $arr2
, т. Е. Если есть ключ 2nd level building
в $arr2
тогда следует считать совпадение 2nd level
, однако 2nd levelbuilding
не должно совпадать.