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,"