PHP Two-dimensional array cut to a string and remove duplicate values

Source: Internet
Author: User
This article is about the PHP two-dimensional array cut into a string and remove duplicate values of the code, now share to everyone, the need for friends can refer to

The scenario is that you need to query a rent_contract_id for all the relevant IDs and rent_contract_parent_id, and then assemble them into strings for later use Find_in_set query operations:

Select rent_contract_id,rent_contract_parent_id from tb_rent_contract where rent_contract_id =797 or rent_contract_ parent_id = 797$arr = Array (Array (' rent_contract_id ' =>555, ' rent_contract_parent_id ' =>666), array (' Rent_ contract_id ' =>777, ' rent_contract_parent_id ' =>555), array (' rent_contract_id ' =>888, ' rent_contract_parent _id ' =>777); $str _arr = ""; An empty string that facilitates the traversal of the append foreach ($arr as $ke + = $va) {  $str _arr. = Implode (', ', $va). ",";} $arr _str = Explode (",", $str _arr); String assembly is an array of $arr_str = Array_unique ($arr _str);//Remove duplicate values $str = Implode (', ', $arr _str);     Split into String var_dump ($STR);                   String (16) "555,666,777,888,"

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.