Arrays with same element and grab one in php -
i have array consist of further sub arrays like
array ( [0] => mm [1] => cm [2] => inch ) array ( [0] => mm [1] => cm [2] => inch )
since both arrays have same elements try fetch 1 that.i try array_unique(),merge function didn't succeed.i can remove 1 array using foreach loop want know if possible single statement, bulitin function or 1 line code not more that.hopes got point.i trying reduce code
if question, trying remove duplicate subarrays. try this
$input = array_map("unserialize", array_unique(array_map("serialize", $input)));
array_unique removes duplicates array.
array_map takes 2 arguments
array_map ( callable $callback , array $arr1 [, array $... ] )
it recursively runs callback on array
basically code serializes array's content (each sub-array in case), removes duplicates unserialize content recreate original array
more here: how remove duplicate values array in php
Comments
Post a Comment