简体   繁体   中英

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. i am trying to use splstack but i have not any idea to how to use it. 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; or change your object creation by this. new \SplStack .

Read more from here https://www.php.net/manual/en/class.splstack.php

In order to use another controller in your file, you need to "import" it first. You must specify the controller and it's filepath. Such as, you need to write this at the top of your file if you wish to use a controller called LoginController:

use App\Http\Controllers\LoginController;

I do not know where SplStack is located so I can not specify your path for you. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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