我需要帮助才能获得此数组的配对值:
数组$requestedFields
:
Array
(
[0] => id
[1] => first-name
[2] => last-name
[3] => username
[4] => email
[5] => truntt
[6] => fiff
)
数组$apiFields
:
Array
(
[0] => Array
(
[0] => id
[1] => id
[2] => accounts.profile.basic
)
[1] => Array
(
[0] => first-name
[1] => fname
[2] => accounts.profile.basic
)
[2] => Array
(
[0] => last-name
[1] => lname
[2] => accounts.profile.basic
)
[3] => Array
(
[0] => username
[1] => username
[2] => accounts.profile.basic
)
[4] => Array
(
[0] => email
[1] => email
[2] => accounts.profile.emailaddress
)
[5] => Array
(
[0] => test-test
[1] => test
[2] => accounts.profile.test
)
)
我需要获得与$apiFields
匹配的$requestedFields
元素,在这种情况下只有0-4个元素值。
任何帮助表示赞赏。
答案 0 :(得分:4)
使用以下代码:
foreach($apiFields as $key=>$arr){
if(!in_array($arr[0], $requestedFields)){
unset($apiFields[$key]);
}
}
它会在$apiFields
数组中为您提供预期的结果。