<small id='ST1ev'></small><noframes id='ST1ev'>

        <tfoot id='ST1ev'></tfoot>

        <i id='ST1ev'><tr id='ST1ev'><dt id='ST1ev'><q id='ST1ev'><span id='ST1ev'><b id='ST1ev'><form id='ST1ev'><ins id='ST1ev'></ins><ul id='ST1ev'></ul><sub id='ST1ev'></sub></form><legend id='ST1ev'></legend><bdo id='ST1ev'><pre id='ST1ev'><center id='ST1ev'></center></pre></bdo></b><th id='ST1ev'></th></span></q></dt></tr></i><div id='ST1ev'><tfoot id='ST1ev'></tfoot><dl id='ST1ev'><fieldset id='ST1ev'></fieldset></dl></div>
        • <bdo id='ST1ev'></bdo><ul id='ST1ev'></ul>

      1. <legend id='ST1ev'><style id='ST1ev'><dir id='ST1ev'><q id='ST1ev'></q></dir></style></legend>

        PHP 注意:未定义偏移量:1 读取数据时带数组

        时间:2023-09-21
          <tbody id='ul8pn'></tbody>

            <bdo id='ul8pn'></bdo><ul id='ul8pn'></ul>

            1. <i id='ul8pn'><tr id='ul8pn'><dt id='ul8pn'><q id='ul8pn'><span id='ul8pn'><b id='ul8pn'><form id='ul8pn'><ins id='ul8pn'></ins><ul id='ul8pn'></ul><sub id='ul8pn'></sub></form><legend id='ul8pn'></legend><bdo id='ul8pn'><pre id='ul8pn'><center id='ul8pn'></center></pre></bdo></b><th id='ul8pn'></th></span></q></dt></tr></i><div id='ul8pn'><tfoot id='ul8pn'></tfoot><dl id='ul8pn'><fieldset id='ul8pn'></fieldset></dl></div>

                1. <legend id='ul8pn'><style id='ul8pn'><dir id='ul8pn'><q id='ul8pn'></q></dir></style></legend><tfoot id='ul8pn'></tfoot>

                  <small id='ul8pn'></small><noframes id='ul8pn'>

                  本文介绍了PHP 注意:未定义偏移量:1 读取数据时带数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我收到此 PHP 错误:

                  I am getting this PHP error:

                  PHP Notice:  Undefined offset: 1
                  

                  这是抛出它的 PHP 代码:

                  Here is the PHP code that throws it:

                  $file_handle = fopen($path."/Summary/data.txt","r"); //open text file
                  $data = array(); // create new array map
                  
                  while (!feof($file_handle) ) {
                      $line_of_text = fgets($file_handle); // read in each line
                      $parts = array_map('trim', explode(':', $line_of_text, 2)); 
                      // separates line_of_text by ':' trim strings for extra space
                      $data[$parts[0]] = $parts[1]; 
                      // map the resulting parts into array 
                      //$results('NAME_BEFORE_:') = VALUE_AFTER_:
                  }
                  

                  这个错误是什么意思?导致此错误的原因是什么?

                  What does this error mean? What causes this error?

                  推荐答案

                  更改

                  $data[$parts[0]] = $parts[1];
                  

                  if ( ! isset($parts[1])) {
                     $parts[1] = null;
                  }
                  
                  $data[$parts[0]] = $parts[1];
                  

                  或者简单地说:

                  $data[$parts[0]] = isset($parts[1]) ? $parts[1] : null;
                  

                  并非文件的每一行都有一个冒号,因此在它上面爆炸会返回一个大小为 1 的数组.

                  Not every line of your file has a colon in it and therefore explode on it returns an array of size 1.

                  根据php.net 可能从explode返回值:

                  返回通过在分隔符形成的边界上拆分字符串参数而创建的字符串数组.

                  Returns an array of strings created by splitting the string parameter on boundaries formed by the delimiter.

                  如果分隔符是一个空字符串 (""),explode() 将返回 FALSE.如果分隔符包含字符串中不包含的值并且使用负限制,则返回空数组,否则返回包含字符串的数组.

                  If delimiter is an empty string (""), explode() will return FALSE. If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned, otherwise an array containing string will be returned.

                  这篇关于PHP 注意:未定义偏移量:1 读取数据时带数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP 未定义索引错误 $_FILES? 下一篇:PHP中变量名前的'At'符号:@$_POST

                  相关文章

                  最新文章

                  <i id='gO79p'><tr id='gO79p'><dt id='gO79p'><q id='gO79p'><span id='gO79p'><b id='gO79p'><form id='gO79p'><ins id='gO79p'></ins><ul id='gO79p'></ul><sub id='gO79p'></sub></form><legend id='gO79p'></legend><bdo id='gO79p'><pre id='gO79p'><center id='gO79p'></center></pre></bdo></b><th id='gO79p'></th></span></q></dt></tr></i><div id='gO79p'><tfoot id='gO79p'></tfoot><dl id='gO79p'><fieldset id='gO79p'></fieldset></dl></div>
                  <tfoot id='gO79p'></tfoot>
                  1. <small id='gO79p'></small><noframes id='gO79p'>

                      <bdo id='gO79p'></bdo><ul id='gO79p'></ul>
                  2. <legend id='gO79p'><style id='gO79p'><dir id='gO79p'><q id='gO79p'></q></dir></style></legend>