我有两个数组。第一个数组包含名称(值),它将搜索另一个数组并在结果中检索该数据。我的演示代码是:
第一个阵列 -
Array
(
[0] => CodeConfiguration
[1] => TaxConfiguration
[2] => ObjectAccountConfiguration
[3] => RolePermission
)
第二阵列 -
Array
(
[submit] =>
[CompanyID] => 1
[BranchID] => 46
[AccountID] => 60
[CodeType_032] => 273
[FixedCode] => IT1
[SeriesFormat_033] => 375
[SeriesConcateCharacter] => @
[NumberLength] => 5
[NumberPaddingCharacter] => 2
[EffectiveFromDate] => 2014-02-01
[EffectiveToDate] =>
[ItemGroupID] => 1
[TaxID] => 2
[CalculationType_080] => 372
[ObjectType] => Array
(
[ID] => 12
[Code] => U
[Name] => Uom
[Description] => Uom
[Group_077] => 309
[SubGroup_078] => 324
[RevisionNumber] => 6
[DisplayName] => Uom
[DefaultLedgerType_002] => 103
[DefaultNarration_071] => 268
[CopyTaxesFromParent] => 1
[CheckPermissions] => 1
[IsAdd] => 1
[IsEdit] => 1
[IsDelete] => 1
)
[CodeConfiguration] => Array
(
[0] => Array
(
[ObjectType] => 12
[LineNo] => 1
[CompanyID] => 1
[BranchID] => 46
[AccountID] => 60
[CodeType_032] => 273
[FixedCode] => IT1
[SeriesFormat_033] => 0
[SeriesConcateCharacter] => @
[NumberLength] => 5
[NumberPaddingCharacter] => 2
[EffectiveFromDate] => 2014-02-01
[EffectiveToDate] =>
[CreatedBy] =>
[ModifiedBy] => 22
[CreatedDate] =>
[ModifiedDate] => 2014-04-25 05:10:15
[RevisionNumber] => 6
[IsDirty] =>
)
)
[ObjectAccountConfiguration] => Array
(
[0] => Array
(
[ObjectType] => 12
[LineNo] => 1
[LineType_072] => 0
[ItemType_001] =>
[AccountType_003] =>
[LedgerType_002] =>
[ItemGroupID] =>
[TaxID] =>
[AccountID] =>
[BranchID] => 1
[SchemeID] =>
[LoyaltyID] =>
[CampaignID] =>
[CurrencyID] =>
[TaxGroupID] =>
[ContactType_011] =>
[ContactGroupID] =>
[CompanyID] => 1
[AccountMasterGroupID] =>
[CreatedBy] => 22
[ModifiedBy] => 22
[CreatedDate] => 2014-04-17 05:11:18
[ModifiedDate] => 2014-04-25 05:10:15
[RevisionNumber] => 5
[IsDirty] => 2
)
)
[TaxConfiguration] => Array
(
[0] => Array
(
[LineNo] => 1
[IsDirty] => 1
[ItemGroupID] =>
[TaxID] =>
[CalculationType_080] => 372
[RevisionNumber] => 1
)
)
)
我只想找到第一个数组中的搜索元素到第二个数组,如果它找到则检索数据。所以请建议我一个合适的解决方案。
答案 0 :(得分:0)
你可以这样做:
$result = array_intersect_key($array2, array_flip($array1));
答案 1 :(得分:0)
试试这个:
$result = array();
foreach ($array1 as $array1item)
$result[] = $array2[$array1item];