Example analysis of key and Current,next in PHP, next example Analysis _php tutorial

Source: Internet
Author: User

A case study of key and Current,next in PHP, next example analysis


This paper describes the joint application of key and Current,next in PHP. Share to everyone for your reference, 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 do I remove duplicate values from a $ARRQ array without destroying the array structure?

idea : First the elements in the first two-dimensional array are output using the Array_unique function.
When you output the elements in the second two-dimensional array, you first use array_unique processing, and then remove the elements that already exist in the first two-dimensional array.
When you output the third, you first use array_unique processing, and then remove the elements that already exist in the first and second two-dimensional combined set.
And so on

In short, you first have to Array_unqiue to the weight, and then remove the elements in the preceding array element in the same set.

Here is the code:

<?PHP$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 '); $last =array (); Sets an empty array to compare while ($arr =current ($ARRQ)) {  //echo key ($ARRQ);  $tmp =array_unique ($arr); First, clear the same value for each one-dimensional array itself  if (count ($last) ==0) {    $last =array_merge ($last, $arr);//merge the previous array that has been de-weighed  }  else {// Outputs the remaining one-dimensional array    //echo key ($ARRQ);    foreach ($arr as $ke + $va) {      if (In_array ($arr [$ke], $last))//If an element unset already exists      ($arrq [Key ($ARRQ)] [$ke]); Delete, where the key value of the array element is critical    }    $last =array_merge ($last, $arr);//$last into a collection of previous arrays for next comparison  }  next ($ ARRQ); The pointer moves backwards 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 "
";}? >

The result of the operation is:

More interested in PHP related content readers can view this site: "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", " PHP Date and Time usage summary, PHP Object-oriented Programming primer, PHP string usage Summary, PHP+MYSQL Database Operations Primer, and PHP Common database operations Tips Summary

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • Ways to iterate an array using the Key,value,current,next and prev functions in PHP
    • Analysis of source code of Array_keys and Array_unique functions in PHP
    • PHP recovers array key as a method of number sequence
    • PHP implements the method of sorting the array by the specified key
    • PHP processing JSON string key missing double quotation mark workaround
    • PHP array index key plus quotation mark and unquoted difference
    • How PHP gets the set of a key in a two-dimensional array
    • PHP array current and next usage sharing
    • Example of current, next, and reset function usages in PHP
    • Get the value of the first element of an unknown character key an array group by using the PHP current function

http://www.bkjia.com/PHPjc/1117082.html www.bkjia.com true http://www.bkjia.com/PHPjc/1117082.html techarticle A case study of key and Current,next in PHP is presented, and an example of next example is given to describe the joint application of key and Current,next in PHP. Share to everyone for your reference, specific as ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.