我有一个array_pop()的错误:参数#1($array)必须是数组类型,使用PHP 8.2.7和laravel 10.13.5给出null

cl25kdpy  于 11个月前  发布在  PHP
关注(0)|答案(2)|浏览(134)

我正在学习laravel和php从laracasts教程.在episode 35我有一个错误发生.这是一个数组错误.浏览器上显示的错误消息如下:
类型错误array_pop():参数#1($array)必须是数组类型,给定为null
错误是由这一行引起的

{{ isset($currentCategory) ? ucwords($currentCategory -> name) : 'Categories' }}

字符串
代码如下
会话信息:SESSION_ID = jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj

<header class="max-w-xl mx-auto mt-20 text-center">
        <h1 class="text-4xl">
            Latest <span class="text-blue-500">Laravel From Scratch</span> News
        </h1>

        <h2 class="inline-flex mt-2">By Lary Laracore <img src="./images/lary-head.svg" alt="Head of Lary the mascot"></h2>

        <p class="text-sm mt-14">
            Another year. Another update. We're refreshing the popular Laravel series with new content.
            I'm going to keep you guys up to speed with what's going on!
        </p>

        <div class="space-y-2 lg:space-y-0 lg:space-x-4 mt-8">

            <!--  Category -->
            <div class="relative lg:inline-flex bg-gray-100 rounded-xl">      
                <x-dropdown>
                    <x-slot name ="trigger"  > 
                        <button class="py-2 pl-3 pr-9 text-sm font-semibold w-full lg:w-32 text-left flex lg:inline-flex">
                            {{ isset($currentCategory) ? ucwords($currentCategory -> name) : 'Categories' }}
                            <svg class="transform -rotate-90 absolute pointer-events-none" style="right: 12px;" width="22" height="22" viewBox="0 0 22 22">
                                <g fill="none" fill-rule="evenodd">
                                    <path stroke="#000" stroke-opacity=".012" stroke-width=".5" d="M21 1v20.16H.84V1z">
                                    </path>
                                    <path fill="#222" d="M13.854 7.224l-3.847 3.856 3.847 3.856-1.184 1.184-5.04-5.04 5.04-5.04z"></path>
                                </g>
                            </svg>
                        </button>
                    </x-slot>

                                <a href="/" class="block text-left px-3 text-sm leading-6 hover:bg-blue-500 focus:bg-blue-500 hover:text-white focus:text-white ">
                                All
                                </a>

                                @foreach ($categories as $category )
                                    <a href="/categories/{{ $category -> slug }}" 
                                    class=" 
                                    block text-left px-3 text-sm leading-6 
                                    hover:bg-blue-500 focus:bg-blue-500 hover:text-white focus:text-white 
                                    {{ isset($currentCategory) && $currentCategory -> is( $category )  ? 'bg-blue-500 text-white' : '' }}
                                    " >
                                    {{ ucwords( $category -> name ) }}
                                    </a>
                                @endforeach
                </x-dropdown>
            </div>

            <!-- Other Filters -->
            <div class="relative flex lg:inline-flex items-center bg-gray-100 rounded-xl">
                <select class="flex-1 appearance-none bg-transparent py-2 pl-3 pr-9 text-sm font-semibold">
                    <option value="category" disabled selected>Other Filters
                    </option>
                    <option value="foo">Foo
                    </option>
                    <option value="bar">Bar
                    </option>
                </select>

                <svg class="transform -rotate-90 absolute pointer-events-none" style="right: 12px;" width="22" height="22" viewBox="0 0 22 22">
                    <g fill="none" fill-rule="evenodd">
                        <path stroke="#000" stroke-opacity=".012" stroke-width=".5" d="M21 1v20.16H.84V1z">
                        </path>
                        <path fill="#222" d="M13.854 7.224l-3.847 3.856 3.847 3.856-1.184 1.184-5.04-5.04 5.04-5.04z"></path>
                    </g>
                </svg>
            </div>

            <!-- Search -->
            <div class="relative flex lg:inline-flex items-center bg-gray-100 rounded-xl px-3 py-2">
                <form method="GET" action="#">
                    <input type="text" name="search" placeholder="Find something" class="bg-transparent placeholder-black font-semibold text-sm">
                </form>
            </div>
        </div>
    </header>

C:\Users\Admin\app-first\resources\views\components\web.blade.php

@props(['trigger']) 

<div x-data="{ show: false}" @click.away="show=false"> 
{{-- Trigger --}} 
<div @click = "show =! show "> 
{{ $trigger }} 
</div> 
{{-- Links --}} 
<div x-show="show" class="py-2 absolute bg-gray-100 mt-2 rounded-xl w-full z-50" style="display: none"> 
{{ $slot }} 
</div> 
</div>

Routes\web.php

Route::get('categories/{category:slug}', function(Category $category){ return view('posts', [ 
'posts' => $category->posts, 
'currentCategory' => $category,
'categories' => Category::all(), 
]);


如何修复此错误?

zphenhs4

zphenhs41#

我也遇到了这个错误,你必须从名称属性中删除空格
之前:

<x-slot name ="trigger"  >

字符串
之后:

<x-slot name="trigger">

toiithl6

toiithl62#

array_pop接受数组作为参数,你传递了null,所以你收到了这个错误,要解决这个传递数组,而不是null

$a=array("1","2","3");
    array_pop($a);
    print_r($a);

字符串

相关问题