Match array key with array value PHP -
how match array key array value. array_intersect() match key array. how match key in first array value in second array.
for example array:
$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' );
if use array_intersect(), use match key. want search key array , value array. , output show this:
array ( [1] => text 1 [2] => text 2 [3] => text 4 [4] => text 5 [5] => text 7 )
i got answer, here :
print_r(array_intersect_key($value_array, array_flip($value_key)));
and output show:
array ( [1] => text 1 [2] => text 2 [4] => text 4 [5] => text 5 [7] => text 7 )
Comments
Post a Comment