can any1 suggest a nice method to pass an array in php?
thanx in advance.

Member Avatar for rajarajan2017

Sample:

Index.php

<html>
<body>
	<br>
	<center><h2>Reverse Array</h2></center>
	<form action="Result.php" method="post">
		<center>				
			<br>Please input the contents of the array: 
			<br>
				<?php 
					$the_array = array_fill(0, 5, 1);
					createTextBoxes($the_array, 5);
				?>
			<br><input type="submit" value="Next">
		</center>
	</form>
</body>
</html>
				
<?php 
	function createTextBoxes($the_array, $n){
		for($i = 0; $i < $n; $i++)
			echo "<input type=\"text\" name=\"inp$i\" size=\"3\">";
	}
?>

Result.php

<?php
$resArray = array_fill(0, 5, 1);
for($i = 0; $i < 5; $i++)
	$resArray[$i] = $_POST['inp'.$i];
print_r($resArray);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.