Questions about appending data in PHP

WBOY
Release: 2016-07-06 13:51:58
Original
961 people have browsed it

Example:

<code>$a = "1,3,4";
</code>
Copy after login
Copy after login

How to append data to $a? Before appending, you need to check whether it contains the pre-added number. For example, 5 is not among them, then the result after appending is:

<code>$a = "1,3,4,5";
</code>
Copy after login
Copy after login

How to achieve this?

Reply content:

Example:

<code>$a = "1,3,4";
</code>
Copy after login
Copy after login

How to append data to $a? Before appending, you need to check whether it contains the pre-added number. For example, 5 is not among them, then the result after appending is:

<code>$a = "1,3,4,5";
</code>
Copy after login
Copy after login

How to achieve this?

<code>implode(',',array_unique(explode(',',$a)))</code>
Copy after login

Convert to array first, merge, remove duplicates, then convert back

Why not use an array? array_search() checks whether the memory exists. If it does not exist, push it to enter. Finally, impload(l

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template