简体   繁体   English

Class 未找到“App\Http\Controllers\SplStack”

[英]Class "App\Http\Controllers\SplStack" not found

I am new to laravel here i am trying using php splstack on laravel for word to number convert but when i run this code so that its give like this error.我是 laravel 的新手,我正在尝试在 laravel 上使用 php splstack 进行字到数字的转换,但是当我运行这段代码时,它会给出这样的错误。 i am trying to use splstack but i have not any idea to how to use it.我正在尝试使用 splstack 但我不知道如何使用它。 so that i will finding some solution on stack这样我就可以在堆栈上找到一些解决方案

$stack = new SplStack; // Currently not working
             $sum   = 0; // Running total
            $last  = null;
            // echo '<pre>';print_r($parts);echo '</pre>';die;
            foreach ($parts as $part) {
                if (!$stack->isEmpty()) {
                    if ($stack->top() > $part) {
                        if ($last >= 1000) {
                            $sum += $stack->pop();
                            $stack->push($part);
                        } else {
                            $stack->push($stack->pop() + $part);
                        }
                    } else {
                        $stack->push($stack->pop() * $part);
                    }
                } else {
                    $stack->push($part);
                }
                $last = $part;
            }

import the SplStack class on top of your controller like as: use SplStack;在 controller 之上导入 SplStack class,如下所示: use SplStack; or change your object creation by this.或通过此更改您的 object 创建。 new \SplStack . new \SplStack

Read more from here https://www.php.net/manual/en/class.splstack.php从这里阅读更多信息https://www.php.net/manual/en/class.splstack.php

In order to use another controller in your file, you need to "import" it first.为了在您的文件中使用另一个 controller,您需要先“导入”它。 You must specify the controller and it's filepath.您必须指定 controller 及其文件路径。 Such as, you need to write this at the top of your file if you wish to use a controller called LoginController:例如,如果你想使用一个名为 LoginController 的 controller,你需要在你的文件的顶部写这个:

use App\Http\Controllers\LoginController;使用 App\Http\Controllers\LoginController;

I do not know where SplStack is located so I can not specify your path for you.我不知道 SplStack 位于何处,因此无法为您指定路径。 But you must write the full path in order to import the file.但是您必须写完整路径才能导入文件。 I also suggest reading the documentation a bit more before engaging in coding to avoid future issues.我还建议在进行编码之前多阅读文档以避免将来出现问题。 You seem to be just starting to learn.你似乎才刚刚开始学习。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM