简体   繁体   English

注意:未定义偏移量:1 in C:\\xampp\\htdocs\\index.php 第 5 行

[英]Notice: Undefined offset: 1 in C:\xampp\htdocs\index.php on line 5

Here is my php code,i searched about the solution but even after adding var_dump($request);这是我的 php 代码,我搜索了解决方案,但即使添加了var_dump($request); i got the same Notice< Notice: Undefined offset: 1 in C:\\xampp\\htdocs\\index.php on line 5 >.我得到了同样的通知< Notice: Undefined offset: 1 in C:\\xampp\\htdocs\\index.php on line 5 >。

index.php索引.php

<?php 
$rd = dirname(__FILE__);
$request[]='';
var_dump($request);
if ($request[1] == '')
  {
        $request[1] = 'header';
    include($rd.'/php_includes/'.$request[1].'.php');
  }


if ($request[0] == '')
  {
    $request[0] = 'index';
    include($rd.'/php_includes/'.$request[0].'.php');
  }

?>

Could you please Help me out with this?你能帮我解决这个问题吗?

Initially, $request doesn't exist. 最初, $request不存在。 You add one element with $request=[]'' , so now you have $request[0] set. 您添加了一个带有$request=[]''元素,因此现在您已经设置了$request[0] Shortly thereafter, you reference $request[1] without it being first defined. 此后不久,您将引用$request[1]而不先对其进行定义。 There is no $request[1] , which is why you're getting this notice. 没有$request[1] ,这就是为什么您收到此通知的原因。

Your line that checks to see if it has a value, and throws the notice because it's not set, is this one: 您要检查的行是否具有值,并由于未设置而引发通知,您的这一行是:

if ($request[1] == '')

If you want to check to see if it's empty without throwing a notice, use this: 如果要检查它是否为空而不发出通知,请使用以下命令:

if (empty($request[1]))

This will return TRUE if $request[1] is not set, is set to NULL , empty, or 0; 如果未设置$request[1] ,将其设置为NULL ,空或0,则返回TRUE so it should accomplish what you're trying to do without throwing a notice. 因此它应该完成您尝试做的事情而不会发出通知。

You are getting the error because youare calling $request[1] when it is not set. 您收到错误是因为未设置$ request [1]时会调用它。 If you want $request to be declared as an empty array do it like: 如果要将$ request声明为空数组,请执行以下操作:

$request = array();

if you want to check if it is set or empty 如果要检查它是否已设置或为空

if (!isset($request[1]) || empty($request[1]))
{
    //your code here in case of not existing or being empty
}

$request[] = ''; // adds a value to the next key - they are autogenerated from 0 as int 0 1 2 3 4 5 6 and so on, if you don't declare them otherwise
<?php
    include("db.php");
    $query = "SELECT * FROM `tbl_user` ORDER BY id DESC";
    $statement = mysqli_query($connect,$query);
    // if(count($data)>0){
        while($row = mysqli_fetch_assoc($statement))
        {
            echo $row[1];
        }   

暂无
暂无

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

相关问题 注意:尝试访问 C:\\xampp\\htdocs\\res\\index.php 中第 97 行名称类型为 null 的数组偏移量: - Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\res\index.php on line 97 name: 注意:尝试在第5行的C:\\ xampp \\ htdocs \\ ihelploginapi \\ index.php中获取非对象的属性 - Notice: Trying to get property of non-object in C:\xampp\htdocs\ihelploginapi\index.php on line 5 注意:未定义的偏移量:第19行的C:\\ xampp \\ htdocs \\ h_php \\ addTimes.php中的1 - Notice: Undefined offset: 1 in C:\xampp\htdocs\h_php\addTimes.php on line 19 注意:第21行的C:\\ xampp \\ htdocs \\ isan \\ hasildata.php中的未定义偏移量:0 - Notice: Undefined offset: 0 in C:\xampp\htdocs\isan\hasildata.php on line 21 数组([&#39;1&#39;] =&gt; 1)1注意:未定义的偏移量:第152行的C:\\ xampp \\ htdocs \\ HR \\ functions \\ functions_applicants.php中的1 - Array ( ['1'] => 1 ) 1 Notice: Undefined offset: 1 in C:\xampp\htdocs\HR\functions\functions_applicants.php on line 152 2 注意:Undefined offset: 2 in C:\\xampp\\htdocs\\test.php on line 20 如何解决 - Notice: Undefined offset: 2 in C:\xampp\htdocs\test.php on line 20 how to solve 注意:未定义的索引:在线的C:\\ xampp \\ htdocs \\ cars \\ index1.php中的elegido - Notice: Undefined index: elegido in C:\xampp\htdocs\cars\index1.php on line PHP:注意:未定义的索引:第9行的C:\\ xampp \\ htdocs \\ vdab \\ cookies.php中的NameFilledIn - PHP : Notice: Undefined index: NameFilledIn in C:\xampp\htdocs\vdab\cookies.php on line 9 未定义的索引:在第29行的C:\\ xampp \\ htdocs \\ index.php中提交 - Undefined index: submit in C:\xampp\htdocs\index.php on line 29 php注意:未定义的索引:第3行的C:\\ xampp \\ htdocs \\ includes \\ middle.php中的id - php Notice: Undefined index: id in C:\xampp\htdocs\includes\middle.php on line 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM