Click here to Skip to main content
15,898,991 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
See the code below: I want to print all the values of $tog.
If you giv name1="some" and name2="thing" I should get some.thing and second time name1="qwe" and name2="rty" I shoud get some.thing and qwe.rty .
Previous value of $tog also I need to get.
Pls help me to solve this.

What I have tried:

<form method="post">
<input type="text" name="name1">
<input type="text" name="name2">
<input type="submit" value="submit">
</form>

<?php
$name1=$_POST['name1'];
$name2=$_POST['name2'];
$tog=$name1.$name2;
?>
Posted
Updated 11-Dec-17 2:23am

You are using string concatenation to create $tog (PHP: String Operators - Manual[^]). So that is a string variable containing only a single value.

You might create a concatenated string by inserting a separation character:
PHP
$tog = $name1 . '.' . $name2;
Then it can be later splitted into the original strings provided that those did not contain the separation character.

You might use a string array instead (PHP: Arrays - Manual[^]):
PHP
$tog = array($name1, $name2);
To print all values from such an array:
PHP
$count = count($array);
for ($i = 0; $i < $count; $i++) {
    if ($count > 0) {
        echo ".";
    }
    echo $array[$i];
}
echo "\n";
 
Share this answer
 
If you need such work, please try to use arrays of data in php, then print the array
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900