我有两个从csv文件转换而来的数组。 第一个csv行看起来像这样:
franchise_id,franchise_name,phone,website,email,region_codes;
1,"Abbott, Hackett and O`Conner",1-648-177-9510,auto-service.co/bw-319-x,Lupe-2485@auto-service.co,"36101,36055,36071";
第二个csv行看起来像这样:
postal_code,region_code,city,state,region;
14410,36055,Adams Basin,NY,Monroe;
我将这些行转换为这样的数组:
//Region Array
$region_lines = explode(PHP_EOL, $region_mappings_string);
$region_array = array();
foreach ($region_lines as $region_line) {
$region_array[] = str_getcsv($region_line);
}
//Franchise Array
$franchise_lines = explode(PHP_EOL, $franchises_string);
$franchise_array = array();
foreach ($franchise_lines as $franchise_line) {
$franchise_array[] = str_getcsv($franchise_line);
}
之后我得到了这样的结果:Region:
Array
(
[0] => Array
(
[0] => postal_code
[1] => region_code
[2] => city
[3] => state
[4] => region;
)
[111] => Array
(
[0] => 14410
[1] => 36055
[2] => Adams Basin
[3] => NY
[4] => Monroe;
)
[112] => Array
(
[0] => 14617
[1] => 36055
[2] => Rochester
[3] => NY
[4] => Monroe;
)
特许经营:
Array
(
[0] => Array
(
[0] => franchise_id
[1] => franchise_name
[2] => phone
[3] => website
[4] => email
[5] => region_codes;
)
[1] => Array
(
[0] => 1
[1] => Abbott, Hackett and O`Conner
[2] => 1-648-177-9510
[3] => auto-service.co/bw-319-x
[4] => Lupe-2485@auto-service.co
[5] => 36101,36055,36071;
)
我需要做的是从第一个数组中查找14410邮政编码,获取region_code并在第二个数组中查找此region_code,然后以PHP格式输出结果。怎么办呢?
答案 0 :(得分:2)
将不得不循环遍历特许经营数组并进行简单的比较
animateCState