dsmgcse8876 2011-07-03 21:59
浏览 54
已采纳

PHP中的变量未定义

I have 5 fields in my DB:

test1 = 1, test2 = 1, test3 = NULL, test4 = NULL, test5 = NULL

PHP code:

if(isset($result['test1'])){$test1= "Test1"; echo $test1};

if(isset($result['test2'])){$test2= "Test2"; echo $test2};

if(isset($result['test3'])){$test3= "Test3"; echo $test3};

if(isset($result['test4'])){$test4= "Test4"; echo $test4};

if(isset($result['test5'])){$test5= "Test5"; echo $test5};

$total = implode(", ", array_filter(array($test1, $test2, $test3, $test4, $test5)));

echo $total;

Finaly Output:

Undefined Variable test3 in Line 7

Undefined Variable test4 in Line 7

Undefined Variable test5 in Line 7

Test1, Test2

I came up with 3 possible ways to hopefully run the code with NULL values to see if I will get a blank page with no error, unfortunately, they all gave me "Underfined Variable" error:

  1. if(isset($result['test3'])){$test3= "OK"; echo $test3};

  2. if(!empty($result['test3'])){$test3= "OK"; echo $test3};

  3. if($result['test3']=='1'){$test3= "OK"; echo $test3};

Help? Thanks in Advance!

  • 写回答

2条回答 默认 最新

  • dongna2498 2011-07-03 22:05
    关注
    if(isset($result['test1'])){$test1= "Test1"; echo $test1} else { $test1="Abrakadabra"; }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效