Q:

Setting variable and string from POST with loop

Currently I have 100 text input boxes named contact0 through contact101.  I am trying to get the Post data and name each string to itself.  Meaning $contact0 = $_POST['contact0'];all the way up to $contact101 = $_POST['contact101']; there has to be a simpler way to set them in a loop or something.  Overall the end result is I just want the data entered in the textbox to become the value of the textbox when submitted.  Any suggestions will help I might be doing this wrong for the results I want. 
for ($i = 0; ;$i++){
if($i < 101){
$contact.$i = $_POST['contact'].$i;
echo $contact.$i;
}
else{
break;
}
}

A:

You may want to consider amending your HTML form.  Rather than create 100 new variables, you can assign all the contacts to an array and then reference them with the array index. 
HTML
<input type="text" name="contacts[]" value="Contact 1 name"/>
<input type="text" name="contacts[]" value="Contact 2 name"/>
// etc...

PHP
$contacts = $_POST['contacts'];
var_dump($contacts);
// prints array(0 => 'Contact 1 Name', 1 => 'Contact 2 Name'...

As it now an array, you can reference the contact e.g. $contacts[34] and know it will be a valid entry.  
EDIT
A working example:
<? php
    if (isset($_POST['contacts'])) {
        $contacts = $_POST['contacts'];
        echo "<p>The contacts are below:</p>";
        print_r($contacts);
    } else {
        echo "<p>Please enter the contacts</p>";
    }
? >

<form method="post" action="">
    <? php for($x = 0; $x < 100; $x++): ? >
    <input type="text" name="contacts[]" value="<?php echo (isset($contacts[$x])) ?  $contacts[0] : ''; ? >"/>
    <? php endfor; ? >
    <input type="submit" name="submit" value="submit"/>
</form>

Edit 2
I have now made the form a loop, meaning it will create all our contact inputs for us.  On top of this, if we have already posted the form each field will have the correct contact values.  
If you are not aware of the syntax, echo isset($contacts[$x])) ?  $contacts[$x] : ''; is a ternary operator which is a one line if/else statement. 
Which can also be tested here: http://phpfiddle.org/api/run/ugb-cta

