PHP How to get the intersection of two or more arrays -
i trying intersection of 2 or more arrays kind of structure:
first array:
array( [0] => array( ['room_id'] => 21 ['room_name'] => 'gb 101' ['capacity'] => 40 ) [1] => array( ['room_id'] => 22 ['room_name'] => 'h 114' ['capacity'] => 20 ) [2] => array( ['room_id'] => 23 ['room_name'] => 'gb 203' ['capacity'] => 20 ) [3] => array( ['room_id'] => 25 ['room_name'] => 'h 100' ['capacity'] => 30 ) [4] => array( ['room_id'] => 26 ['room_name'] => 'gb 206' ['capacity'] => 40 ) )
second array:
array( [0] => array( ['room_id'] => 21 ['room_name'] => 'gb 101' ['capacity'] => 40 ) [1] => array( ['room_id'] => 23 ['room_name'] => 'gb 203' ['capacity'] => 20 ) [2] => array( ['room_id'] => 26 ['room_name'] => 'gb 206' ['capacity'] => 40 ) )
resulting array:
array( [0] => array( ['room_id'] => 21 ['room_name'] => 'gb 101' ['capacity'] => 40 ) [1] => array( ['room_id'] => 23 ['room_name'] => 'gb 203' ['capacity'] => 20 ) [2] => array( ['room_id'] => 26 ['room_name'] => 'gb 206' ['capacity'] => 40 ) )
i tried using array_intersect_assoc intersection using following code:
$result = call_user_func_array('array_intersect_assoc', $arrays);
it trick gives following warning expected according here:
a php error encountered
severity: notice
message: array string conversion
i making ajax based system error messes up. there way intersection of arrays?
try serializing them:
$result = array_map('unserialize', array_intersect( array_map('serialize', $first), array_map('serialize', $second)));
Comments
Post a Comment