Home >Backend Development >PHP Tutorial >Sample code for dedecms topic node ID that cannot be repeated

Sample code for dedecms topic node ID that cannot be repeated

黄舟
黄舟Original
2017-03-31 09:45:181397browse

This article mainly introduces the solution to the problem that the dedecms topic node ID cannot be repeated. Friends in need can refer to the

dedecms template download address: www.php.cn/xiazai/code/dedecms

When I was working on a special topic, I discovered a particularly depressing thing. There are 5 nodes. Duplicate IDs in any node are filtered and written to the database. After some research, it turns out that there is a deduplication function.

Finally, the culprit was found to be the following code:

if(is_array($ids))
            {
                foreach($ids as $mid)
                {
                    $mid = trim($mid);
                    if($mid=="") continue;
                    if(!isset($arcids[$mid]))
                    {
                        if($okids=="")
                        {
                            $okids .= $mid;
                        }
                        else
                        {
                            $okids .= ",".$mid;
                        }
                        $arcids[$mid] = 1;
                    }
                }
            }

s Among them, in the foreach loop, there is an isset judgment, which filters out some duplicate IDs;
I don’t know how the variable of DEDE $arcids is set. After the foreach loop, the IDs assigned to all nodes will be entered into the array.
To this end, my solution is as follows:
First deduplicate the $ids array variable:

$ids = array_unique($ids);

Then change isset to is_array to determine whether it is an array
Complete The code is as follows:

$ids = array_unique($ids);
            if(is_array($ids))
            {
                foreach($ids as $mid)
                {
                    $mid = trim($mid);
                    if($mid=="") continue;
                    if(!is_array($arcids[$mid]))
                    {
                        if($okids=="")
                        {
                            $okids .= $mid;
                        }
                        else
                        {
                            $okids .= ",".$mid;
                        }
                        $arcids[$mid] = 1;
                    }
                }
            }

I don’t know if such a change will have other "side effects"! I hope you can give me some advice!

The above is the detailed content of Sample code for dedecms topic node ID that cannot be repeated. For more information, please follow other related articles on the PHP Chinese website!

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