简体   繁体   English

我收到错误通知:我的代码php中的数组到字符串的转换

[英]I got Error Notice: Array to string conversion in my code php

hi guys i got problem in my code i don't know where come form this my code 嗨,大家好,我的代码有问题,我不知道我的代码从哪里来

<h1><?php echo $item["title"]; ?> </h1>
       <table>
          <tr>
             <th>Catageory</th>
             <td><?php echo $item["category"]; ?></td>
         </tr> 
         <tr>
             <th>Genre</th>
             <td><?php echo $item["genre"]; ?></td>
         </tr> 
         <tr>
             <th>Format</th>
             <td><?php echo $item["format"]; ?></td>
         </tr> 
         <tr>
             <th>Year</th>
             <td><?php echo $item["year"]; ?></td>
         </tr> 
         <?php
         if(strtolower($item["category"]) == "books"){
             ?>
        <tr>
             <th>Authors</th>
             <td><?php echo $item["authors"]; ?></td>
         </tr> 

        <tr>
             <th>Publisher</th>
             <td><?php echo $item["publisher"]; ?></td>
         </tr> 
        <tr>
             <th>ISBN</th>
             <td><?php echo $item["isbn"]; ?></td>
         </tr>           

    <?php    }  ?>

And the error message, 和错误消息,

and Iam sure all code are same i don't what's problem !! 而且我敢肯定,所有代码都是一样的,我没有什么问题!

在此处输入图片说明

As per your image, you are trying to print string on line 58, but you are getting array from your resultant query. 根据您的图像,您尝试在第58行上打印字符串,但是从结果查询中获取数组。 So try to var_dump($yourvar) and check that are you getting required string or an array 因此,尝试var_dump($ yourvar)并检查您是否正在获取所需的字符串或数组

You are trying to echo an array variable which is not right. 您正在尝试回显不正确的数组变量。 Use the below debug code and you have to parse the array however you want. 使用下面的调试代码,您必须根据需要解析该数组。

    Authors ->  <?php echo "<pre>";print_r($item["authors"]);echo "<pre>"; ?>

my problem is solved 我的问题解决了

by replace 通过替换

             <td><?php echo $item["authors"]; ?></td>

to

<td><?php echo implode(",", $item["authors"]); ?></td>

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

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