douping1993 2014-05-24 23:27
浏览 67
已采纳

为什么我的.Explode()不能处理字符串[关闭]

I am trying to explode a string into a list based off comma's, I have done this before but for some reason this not working now.

Just for reference, the line where I called echo echo $members[6]; returns 2009, 7, 146, 277.00, Company 6 so I know everything is being stored properly into $members

I also know from calling $arrlength it returns the correct size of strings that I populate into $members.

So I have the right data and it is formatted correctly yet the ONLY lines that print on my index.php is the echo $members[6]; statement and since I have a VERY long scroll bar I am also guessing that echo "<br><br>"; prints too.

Any help would be greatly appreciated.

<html>
<head>
</head>
<body>

<?php
$str_data = file_get_contents("file.json");
$data = json_decode($str_data,true);

foreach ($data as $key => $value) 
{   
    foreach ($value as $k => $v) 
    { 
       $t = "";
        foreach ($v as $kk => $vv) 
        { 
             $t = $t . ", " . $vv;         
        }
        $members[] = substr($t, 2); //cuts out initial comma + space      
    }
}
$arrlength=count($members);

echo $members[6]; // returns 2009, 7, 146, 277.00, Company 6

for ($i=0; $i<$arrlength; $i++) 
{
     list($year, $rank, $revenue, $profit, $company) = explode(",", $members[i]);
     $year = trim($year);
     $rank = trim($rank);
     $revenue = trim($revenue);
     $profit = trim($profit);
     $company = trim($company);

     echo $year;
     echo $rank;
     echo $revenue;
     echo $profit;
     echo $company;
     echo "<br><br>";   
     }
?> 
</body>
</html>
  • 写回答

2条回答 默认 最新

  • duanjian9148 2014-05-24 23:35
    关注

    It does not work because you missed the $:

    explode(",", $members[i]);
    

    Should be:

    explode(",", $members[$i]);
    

    You should turn on errors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料