In PHP, key, current, and next are combined with instance analysis and next instance analysis.
This article describes how to use key, current, and next in PHP. We will share this with you for your reference. The details are as follows:
Problem:
$arrq = array();$arrq['tuc'] = array('sss'=>'ewq','shu'=>'sjkah','saa'=>'dwjhaz');$arrq['tucs'] = array('ssss'=>'ewsq','sQhu'=>dwjhaz','sa12a'=>'dwjQhaz');$arrq['tuca'] = array('sssd'=>'ewqq','shu2'=>'sjkah','saSa'=>'dwjhhaz');
How can we remove the repeated values in the $ arrq array without damaging the array structure?
Ideas: First, output the elements in the first two-dimensional array using the array_unique function.
When outputting the elements in the second two-dimensional array, you first use array_unique to process the elements, and then drop them into the existing elements in the first two-dimensional array.
When outputting the third data, you first use array_unique for processing, and then drop the existing elements in the first and second two-dimensional data combination sets.
And so on.
In short, you must first remove the array_unqiue and then remove the elements existing in the array element collection in front of you.
The following code is used:
<? Php $ arrq = array (); $ arrq ['tuc'] = array ('ss' => 'ewq', 'shu' => 'sjkah ', 'saa '=> 'dwjhaz'); $ arrq ['ucs'] = array ('sss' => 'wsq', 'sqhu' => 'dwjhaz ', 'sa12a' => 'dwjqhaz'); $ arrq ['tuca'] = array ('sssd' => 'ewqq', 'shu2 '=> 'sjkah ', 'sasa '=> 'dwjhhaz'); $ last = array (); // set an empty array for comparison while ($ arr = current ($ arrq )) {// echo key ($ arrq); $ tmp = array_unique ($ arr); // first clear the same value of each one-dimensional array if (count ($ last) = 0) {$ last = array_merge ($ last, $ ar R); // merge the previously deduplicated arrays} else {// output the remaining one-dimensional arrays // echo key ($ arrq ); foreach ($ arr as $ ke => $ va) {if (in_array ($ arr [$ ke], $ last )) // if the existing element unset ($ arrq [key ($ arrq)] [$ ke]); // Delete, the KEY value of the array element is the KEY} $ last = array_merge ($ last, $ arr); // Changes $ last to the collection of the previous array, used for the next comparison} next ($ arrq); // move the pointer back, in this way, the key function can be used to obtain different $ arrq subscript} // The following output processed array foreach ($ arrq as $ arr) {foreach ($ arr as $ val) {echo $ val. "" ;}echo "<br>" ;}?>
The running result is: