remove element from array php -
my first array like:
array ( [0] => array ( [column_name] => ben_firstname ) )
second array:
array ( [0] => array ( [column_name] => ben_unique_id ) [1] => array ( [column_name] => ben_firstname ) [2] => array ( [column_name] => ben_lastname ) [3] => array ( [column_name] => ben_middlename ) )
i want remove ben_firstname (which in first array) second array...
i tried array_diff
function. but, getting error.
code:
print_r(array_diff($first_array, $second_array));
error:
message: array string conversion
thanks help.
you can't use array_diff
directly because function expects array elements scalar, while in case arrays.
the correct solution use array_udiff
callback determines equality looking @ column_name
key of each array:
$result = array_udiff( $second, $first, function($x, $y) { return strcmp($x['column_name'], $y['column_name']); } );
Comments
Post a Comment