简体   繁体   English

给数组元素赋值时未定义的索引

[英]Undefined index when assigning value to array element

In while loop I'm assigning value pulled from DB to the array like so: 在while循环中,我将从DB拉出的值分配给数组,如下所示:

$states[$row['state']]

PHP gives me the following notice: PHP给我以下通知:

Notice: Undefined index: ME in /var/www/vhosts/basementfinishing-md-de.com/httpdocs/inc/class.cityBlock.php on line 67 注意:未定义的索引:第67行/var/www/vhosts/basementfinishing-md-de.com/httpdocs/inc/class.cityBlock.php中的ME

What I'm doing wrong here? 我在这里做错了什么?

这意味着$row['state']是'ME',并且未为$states定义此索引。

I don't have enough context to interpret the error message 100%, but I've been known to do something like this: 我没有足够的上下文来解释错误消息100%,但是众所周知,我会做这样的事情:

      $states = array();
      while ($row = mysql_fetch_assoc($result)) {
        array_push($states, $row['state']);
      }

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

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