Skip to content

Instantly share code, notes, and snippets.

@NayrMorales
Last active January 20, 2019 07:13
Show Gist options
  • Select an option

  • Save NayrMorales/9d6a19bef8457d3701a018be775564d1 to your computer and use it in GitHub Desktop.

Select an option

Save NayrMorales/9d6a19bef8457d3701a018be775564d1 to your computer and use it in GitHub Desktop.
Return unique string array with insensitive case and merge with array value count
<?php
$array1 = array(
0 => Green,
1 => green,
3 => Yellow,
5 => yellow,
);
$array2 = array(
0 => 12,
1 => 33,
2 => 2,
3 => 21,
4 => 54,
5 => 9,
);
function array_iunique( $array, $array2 ) {
$set = array_intersect_key(
$array,
array_unique( array_map( "strtolower", $array ) )
);
$set2 = array_values($set);
$have_combine = array_diff($set2, $array2);
for($i=0;$i < count($have_combine);$i++){
$merged[] = [
$have_combine[$i] => $array2[$i]
];
}
return $merged;
}
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment