search
HomeBackend DevelopmentPHP TutorialDetailed explanation of return value of infinite classification recursive function in ecshop
Detailed explanation of return value of infinite classification recursive function in ecshopJun 27, 2017 am 09:28 AM
ecshopfunctionClassificationunlimitedrecursion

When doing product classification in the secondary development of ecshopindex, the top-level category id must be obtained based on the category id. The first reaction was to use recursion to pass it out, so I wrote the recursive function as follows:

function getCatTopId($cat_id)
{
    if ($cat_id)
    {
      $res = Array();
        $sql = 'SELECT cat_id, parent_id'
             . ' FROM ' . $GLOBALS['ecs']->table('category') 
             . ' WHERE cat_id = ' . $cat_id . ' AND is_show = 1';
        $res = $GLOBALS['db']->getAll($sql);
        if ($res[0]['parent_id'] > 0)
        {
            getCatTopId($res[0]['parent_id']);
        }
        else
        {
            return $res[0]['cat_id'];
        }
    }
    else
    {
        return 1;
    }
}

A test program, no return value? After checking for a long time, no error was found. It seemed that the circuit in the brain was broken. When I asked Shui Shen (a kind-hearted netizen) today, he helped me answer it, and the modification is as follows:

function getCatTopId($cat_id)
{
    if ($cat_id)
    {
     $res = Array();
        $sql = 'SELECT cat_id, parent_id'
             . ' FROM ' . $GLOBALS['ecs']->table('category') 
             . ' WHERE cat_id = ' . $cat_id . ' AND is_show = 1';
        $res = $GLOBALS['db']->getAll($sql);
        if ($res[0]['parent_id'] > 0)
        {
            return getCatTopId($res[0]['parent_id']); // 修改处,多写个 return ,让函数返回值
        }
        else
        {
            return $res[0]['cat_id'];
        }    }
    else
    {
        return 1;
    }
}

The function is written internally. Even if it returns, it only returns to the position of the internal function, so there is still There is a main function, which must be returned again

The above is the detailed content of Detailed explanation of return value of infinite classification recursive function in ecshop. 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
提高 Python 代码可读性的五个基本技巧提高 Python 代码可读性的五个基本技巧Apr 12, 2023 pm 08:58 PM

Python 中有许多方法可以帮助我们理解代码的内部工作原理,良好的编程习惯,可以使我们的工作事半功倍!例如,我们最终可能会得到看起来很像下图中的代码。虽然不是最糟糕的,但是,我们需要扩展一些事情,例如:load_las_file 函数中的 f 和 d 代表什么?为什么我们要在 clay 函数中检查结果?这些函数需要什么类型?Floats? DataFrames?在本文中,我们将着重讨论如何通过文档、提示输入和正确的变量名称来提高应用程序/脚本的可读性的五个基本技巧。1. Comments我们可

CRPS:贝叶斯机器学习模型的评分函数CRPS:贝叶斯机器学习模型的评分函数Apr 12, 2023 am 11:07 AM

连续分级概率评分(Continuous Ranked Probability Score, CRPS)或“连续概率排位分数”是一个函数或统计量,可以将分布预测与真实值进行比较。机器学习工作流程的一个重要部分是模型评估。这个过程本身可以被认为是常识:将数据分成训练集和测试集,在训练集上训练模型,并使用评分函数评估其在测试集上的性能。评分函数(或度量)是将真实值及其预测映射到一个单一且可比较的值 [1]。例如,对于连续预测可以使用 RMSE、MAE、MAPE 或 R 平方等评分函数。如果预测不是逐点

详解JavaScript函数如何实现可变参数?(总结分享)详解JavaScript函数如何实现可变参数?(总结分享)Aug 04, 2022 pm 02:35 PM

js是弱类型语言,不能像C#那样使用param关键字来声明形参是一个可变参数。那么js中,如何实现这种可变参数呢?下面本篇文章就来聊聊JavaScript函数可变参数的实现方法,希望对大家有所帮助!

ecshop是什么构架ecshop是什么构架Feb 23, 2023 am 09:32 AM

ecshop是“B2C”构架;ecshop是一款B2C独立网店系统,适合企业及个人快速构建个性化网上商店;该系统是基于PHP语言及MYSQL数据库构架开发的跨平台开源程序。

ecshop文章排序方法有哪些ecshop文章排序方法有哪些Jun 16, 2023 am 11:30 AM

ecshop文章排序方法:1、按照发布时间排序,可以通过修改文章的发布时间来控制文章在列表中的排列顺序;2、按照点击量排序,可以通过安装“文章点击排行榜”插件来实现该排序功能,该插件可以统计文章的点击量;3、按照评论数排序,可以通过安装“文章评论排行榜”插件来实现该排序功能,该插件可以统计文章的评论数;4、按照相关度排序,可以通过安装“搜索排名”插件来实现该排序功能。

学Python,还不知道main函数吗学Python,还不知道main函数吗Apr 12, 2023 pm 02:58 PM

Python 中的 main 函数充当程序的执行点,在 Python 编程中定义 main 函数是启动程序执行的必要条件,不过它仅在程序直接运行时才执行,而在作为模块导入时不会执行。要了解有关 Python main 函数的更多信息,我们将从如下几点逐步学习:什么是 Python 函数Python 中 main 函数的功能是什么一个基本的 Python main() 是怎样的Python 执行模式Let’s get started什么是 Python 函数相信很多小伙伴对函数都不陌生了,函数是可

Python面向对象里常见的内置成员介绍Python面向对象里常见的内置成员介绍Apr 12, 2023 am 09:10 AM

好嘞,今天我们继续剖析下Python里的类。[[441842]]先前我们定义类的时候,使用到了构造函数,在Python里的构造函数书写比较特殊,他是一个特殊的函数__init__,其实在类里,除了构造函数还有很多其他格式为__XXX__的函数,另外也有一些__xx__的属性。下面我们一一说下:构造函数Python里所有类的构造函数都是__init__,其中根据我们的需求,构造函数又分为有参构造函数和无惨构造函数。如果当前没有定义构造函数,那么系统会自动生成一个无参空的构造函数。例如:在有继承关系

Python编程:有关函数返回值以及最佳实践基本指导原则Python编程:有关函数返回值以及最佳实践基本指导原则Apr 10, 2023 am 11:31 AM

本篇内容作为以函数为主题的最后一篇,来介绍一下函数返回值以及编写函数的一些基本的最佳实践指导原则。函数输出:返回值函数的返回值是Python领先于竞争对手的东西之一。在大多数其他语言中,函数通常只允许返回一个对象,但是在Python中,你可以返回一个元组——这意味着可以返回任何你想要的东西。这个特性允许程序员编写用其他语言编写的软件要困难得多,或者肯定会更加乏味。我们已经说过,要从函数返回一些东西,我们需要使用return语句,后面跟着我们想要返回的东西。函数体中可以根据需要有多个返回语句。另一

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software