从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
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.

print_r sends $p[$i] to the output buffer and then it returns a boolean result, which will be true (or 1 when echoed out).

So, the solution is simply to not use print_r.

Always read the documentation when you are unsure about something. Pretty much anything you want to know about PHP can be found there.