This article illustrates the joint application of key and Current,next in PHP. Share to everyone for your reference, specific as follows:
Problem:
$ARRQ = Array ();
$ARRQ [' TUC '] = Array (' SSS ' => ' ewq ', ' shu ' => ' Sjkah ', ' saa ' => ' Dwjhaz ');
$ARRQ [' tucs '] = Array (' ssss ' => ' ewsq ', ' sqhu ' =>dwjhaz ', ' sa12a ' => ');
$ARRQ [' tuca '] = Array (' SSSD ' => ' ewqq ', ' shu2 ' => ' Sjkah ', ' saSa ' => ');
How do I get rid of duplicate values in a $ARRQ array without destroying the array structure?
idea : First the elements in the first two-dimensional array are output with the Array_unique function.
When you output an element from a second two-dimensional array, you first use Array_unique to process it, and then remove the element that already exists in the first two-dimensional array.
When you output the third, you first use the Array_unique process, and then remove the elements that already exist in the first and second two-dimensional combination set.
Analogy
In short, you first have to array_unqiue to weight, and then remove the elements of their own in the previous array elements in the same concentration.
The following is code:
<?php
$arrq = Array ();
$ARRQ [' TUC '] = Array (' SSS ' => ' ewq ', ' shu ' => ' Sjkah ', ' saa ' => ' Dwjhaz ');
$ARRQ [' tucs '] = Array (' ssss ' => ' ewsq ', ' sqhu ' => ' Dwjhaz ', ' sa12a ' => ');
$ARRQ [' tuca '] = Array (' SSSD ' => ' ewqq ', ' shu2 ' => ' Sjkah ', ' saSa ' => ');
$last =array (); Sets an empty array to compare while
($arr =current ($ARRQ)) {
//echo key ($ARRQ);
$tmp =array_unique ($arr); First clear each one-dimensional array itself the same value
if (count ($last) ==0) {
$last =array_merge ($last, $arr);//To merge the previous array that has gone heavy
}
Else {//Output
//echo key ($ARRQ) for the remaining one-dimensional array;
foreach ($arr as $ke => $va) {if
in_array ($arr [$ke], $last))//If the existing element
unset ($arrq [Key ($ARRQ)] [$ke]); /delete, where the key value of the array element is critical
}
$last =array_merge ($last, $arr);//change $last into a collection of the preceding array for the next comparison
}
next ($ ARRQ); The pointer is moved back so that the key function can be used to obtain a different $ARRQ subscript
}
//The following output processed array
foreach ($arrq as $arr) {
foreach ($arr as $val) {
echo $val. " ";
}
echo "<br>";
>
The results of the operation are:
More interested in PHP related content readers can view the site topics: "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", " PHP Date and Time usage summary, PHP Introduction to object-oriented Programming, PHP String (String) Usage summary, PHP+MYSQL database Operations Tutorial and PHP Common database operating Skills summary
I hope this article will help you with the PHP program design.