如何匹配数组键和数组值。 with array_intersect() 是匹配key数组。 但是如何将第一个数组中的键与第二个数组中的值匹配。
例如数组:
$value_array=array(
'1'=>'text one',
'2'=>'text two',
'3'=>'text three',
'4'=>'text four',
'5'=>'text five',
'6'=>'text six',
'7'=>'text seven',
'8'=>'text eight',
'9'=>'text nine',
'10'=>'text ten'
);
$key_array=array(
'1'=>'1',
'2'=>'2',
'3'=>'4',
'4'=>'5',
'5'=>'7'
);
如果使用array_intersect(),用于匹配键。我想搜索键数组并获取值数组。输出将如下所示:
Array (
[1] => text one
[2] => text two
[3] => text four
[4] => text five
[5] => text seven
)
最佳答案
我得到了答案,就在这里:
print_r(array_intersect_key($value_array, array_flip($value_key)));
输出将显示:
Array (
[1] => text one
[2] => text two
[4] => text four
[5] => text five
[7] => text seven
)
关于php - 将数组键与数组值 PHP 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35030669/