dongteng0748 2013-04-05 20:40
浏览 126
已采纳

从php中的多维数组中删除最后一个元素

I have a textbox that iterates 5 times and displays values from the textbox into an array.

<form method="post" action="test.php">   
 <?php for($i = 0; $i < 5; $i++) { 
     echo "<input type='text' name='text1[]'/>";    
  } ?>
<input type="submit" name="confirm" value="confirm" />
</form>


<?php
  $text1 = $_POST['text1'];
  $count= count($text1);
  if(isset($_POST['confirm'])) { 
    for($p = 0; $p < $count; $p++) {
       echo print_r($p[$i]);
    }
  }
?>

I want to remove the last value (which is that repeating number 1) from the data and only display the names. The output of above is as follows:-

John1
Jack1
Peter1
Jane1
Jill1
  • 写回答

2条回答 默认 最新

  • dqluw20882 2013-04-05 20:44
    关注
    echo print_r($p[$i]);
    

    print_r prints content of $p[$i] and returns 1 that is passed to echo (and printed next to desired output). You don't need print_r here.

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料