【发布时间】:2019-05-31 11:59:43
【问题描述】:
谁帮我解决这个问题?
56 public static function mostrar_entradas_busqueda($entradas) {
57 $count = count($entradas);
58 for ($i = 1; $i <= $count; $i++) {
59 if ($i % 3 == 1) {
60 ?>
61 <div class="row">
62 <?php
63 }
64 $entradas = $entradas[$i - 1];
65 self::mostrar_entrada_busqueda($entradas);
66
67 if ($i % 3 == 0) {
68 ?>
69 </div>
70 <?php
71 }
72 }
73 if ($i % 3 !== 0) {
74 ?>
75 </div>
76 <?php
77 }
78 }
致命错误:未捕获错误:无法将 Entrada 类型的对象用作 C:\xampp\htdocs\blog\app\EscritorEntradas.inc.php:64 中的数组 跟踪:#0 C:\xampp\htdocs\blog\vistas\buscar.php(81): EscritorEntradas::mostrar_entradas_busqueda(Object(Entrada)) #1 C:\xampp\htdocs\blog\index.php(117): include_once('C:\xampp\htdocs...') #2 {main} 抛出 C:\xampp\htdocs\blog\app\EscritorEntradas.inc.php 第 64 行
【问题讨论】:
-
请在您的函数请求时添加
var_dump($entradas)并共享输出 - 我担心它会反对而不是数组 - 如果是这样,请尝试在while循环之前将其转换为数组。并重命名内部变量 -
这也是我的第一个想法。但检查编辑(在第二个答案中,由 OP 给出);似乎
$entradas是一个合适的数组,因为至少有一次循环体被调用(因此Notice: Undefined variable: entradamsg)。它正在重写将事情完全搞砸的价值。