【问题标题】:Laravel Livewire: How to check if all values in an array is False or True?Laravel Livewire:如何检查数组中的所有值是 False 还是 True?
【发布时间】:2022-01-06 04:35:24
【问题描述】:

如何检查数组中的所有值是全是假还是真?所以我为选择学生创建了一个复选框(wire:model="selectedStudents.{{ $stud->id }}")。

结果数组是这样的 [4 => true 5 => true 6 => false] 如果所有值都为真或假,我需要禁用控制器中的功能。请帮帮我。

【问题讨论】:

标签: laravel laravel-livewire


【解决方案1】:

in_array php 函数应该可以工作。

in_array(true, $this->selectedStudents) {
    // all values are true
} else {
   // 1 + N are false
}

当然,数组总是有项目

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2019-12-17
    相关资源
    最近更新 更多