Home >Backend Development >PHP Tutorial >Questions about appending data in PHP

Questions about appending data in PHP

WBOY
WBOYOriginal
2016-07-06 13:51:58991browse

Example:

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

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>

How to achieve this?

Reply content:

Example:

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

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>

How to achieve this?

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

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

Statement:
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