doushi2047 2014-08-05 23:08
浏览 14
已采纳

未处理的数组值

I put together some code to process the values in an array. However, it appears that only the first line is being printed out. I can verify that the array has a size of 247 (by including a sizeof() check before the loop).

Is there something I am not seeing here? The declaration of my $title variable is :

$title = array();

on a global scope.

function pushTitleChanges()
{
  global $title, $first_name, $last_name;
  $index = 0;

  print_r($title);
  if(is_array($title))
  {
    for($x =0; $x< sizeof($title);$x++)
    {
        echo "The index is " . $index .' '. "and title size is " . sizeof($title);
        echo "<br/>";

        $title = str_replace(array('.', ','), '' , $title[$index]);

        $statement = "UPDATE guest_list_guests
        SET guest_list_guests.title = '{$title}'
        WHERE guest_list_guests.first_name ='{$first_name[$index]}'
        AND guest_list_guests.last_name = '{$last_name[$index]}';";
        $index++;
    }
  }
}
  • 写回答

1条回答 默认 最新

  • dongzouh51192 2014-08-05 23:21
    关注

    You are setting the entire title array to `str_replace(array('.', ','), '' , $title[$index]);' This is overwriting the entire array with a String when it seems you want to only change that index. Hence that line would really be:

     $title[$index] = str_replace(array('.', ','), '' , $title[$index]);
    

    I also recommend using the $x variable you have created, it stores the same value as $index making $index completely unnecessary.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作