Last active
January 20, 2019 07:13
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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