我在php中有这个数组,我想选择那些有dob的所有casenumber,然后选择那些没有任何dob的所有链接。我怎么能在PHP中做到这一点
Array
(
[links] => Array
(
[0] => inquiryDetail.jis?caseId=0101SP085622015&loc=3&detailLoc=DV
[1] => inquiryDetail.jis?caseId=0101SP096462015&loc=3&detailLoc=DV
[2] => inquiryDetail.jis?caseId=050200173642014&loc=20&detailLoc=DSCIVIL
[3] => inquiryDetail.jis?caseId=CAL1432003&loc=65&detailLoc=PGV
)
[case_number] => Array
(
[0] => 0101SP085622015
[1] => 0101SP096462015
[2] => 050200173642014
[3] => CAL1432003
)
[persons] => Array
(
[0] => Walker, Rosemary
[1] => Walker, Rosemary
[2] => Walker, Rosemary
[3] => Walker, Rosemary
)
[dob] => Array
(
[0] => 11/1961
[1] => 11/1961
)
[Party_Type] => Array
(
[0] => Defendant
[1] => Defendant
[2] => Defendant
[3] => Defendant
)
[Court] => Array
(
[0] => Baltimore City District Court 1400 North Ave.
[1] => Baltimore City District Court 1400 North Ave.
[2] => Upper Marlboro District Court
[3] => Prince George\'s County Circuit Court
)
[Case_Type] => Array
(
[0] => Domestic Violence
[1] => Domestic Violence
[2] => CONT
[3] => CIVIL
)
[Case_Status] => Array
(
[0] => CLOSE
[1] => CLOSE
[2] => ACTIVE
[3] => ACTIVE
)
[Filing_Date] => Array
(
[0] => 09/04/2015
[1] => 11/25/2015
[2] => 07/24/2014
[3] => 11/18/2014
)
)
这里所有都是互相关联的键。请帮忙
答案 0 :(得分:0)
如果每个子阵列的索引匹配,则此解决方案有效。如果没有,你应该用子阵列之间的关联来澄清你的问题。
$ array - 您的输入数据。
您将获得包含搜索值的$ result数组。
$result = array(
'links_without_dob' => array(),
'case_number_with_dob' => array()
);
foreach($array['dob'] as $k => $v) {
$result['case_number_with_dob'][] = $array['case_number'][$k];
}
foreach($array['links'] as $k => $v) {
if (array_key_exists($k, $array['dob'])) continue;
$result['links_without_dob'][] = $v;
}
我很高兴看到任何有关改进此解决方案的建议。