Php array comparison value {[0] = & gt; string (9) & quot; limit 29 & quot; [1] = & gt; string (8) & quot; 2_334 & quot; [2] = & gt; string (4) & quot; 1 & quot; [3] php array comparison values
{[0] => string (9) "29th 29" [1] => string (8) "2_334" [2] => string (4) "1" [3] => string (4) "2"
[4] => string (9) "limit 30" [5] => string (8) "5_334" [6] => string (4) "6" [7] => string (4) "10 "}
If the value in front of the separator '-' is the same as the value without '-' in the data, this data is not retrieved.
For example, 29th, because the data contains 1 and [2] => string (4) "1 ",
The final result is only '-' and there are no duplicates.
{[5] => string (8) "5_334 "}
------ Solution --------------------
$ A = array ("000029", "2_334", "1", "2", "000030", "5_334", "6", "10 ");
Var_dump ($ );
$ Keys = array ();
$ Result = array ();
Foreach ($ a as $ val ){
If (is_numeric ($ val ))
$ Keys [] = $ val;
}
Foreach ($ a as $ val ){
If (! Is_numeric ($ val )){
$ Tmp = explode ("_", $ val );
If (count ($ tmp) = 2 &&! In_array ($ tmp [0], $ keys ))
$ Result [] = $ val;
}
}
Var_dump ($ result );
?>
Output:
Array (8 ){
[0] =>
String (4) "29th 29"
[1] =>
String (5) "2_334"
[2] =>
String (1) "1"
[3] =>
String (1) "2"
[4] =>
String (4) "limit 30"
[5] =>
String (5) "5_334"
[6] =>
String (1) "6"
[7] =>
String (2) "10"
}
Array (1 ){
[0] =>
String (5) "5_334"
}
------ Solution --------------------
Very earthy code, but the result is what you need.
PHP code
$Array = array ('1_29', '2_334', '1', '2', '1_30', '5_334', '6', '10' );$ReferArray = array ();$FixArray = array ();$MyArray = array ();foreach ( $Array as $Value ) { if (strpos ( $Value, '_' ) == false) { $ReferArray [] = $Value; } else { $FixArray [] = substr ( $Value, 0, 1 ); $MyArray [] = $Value; }}$FixArray = array_diff ( $FixArray, $ReferArray );foreach ( $FixArray as $Key => $Value ) { echo $MyArray [$Key];}