Page 1 of 1

why array_combine doesn't work?

Posted: Fri Sep 29, 2006 4:46 pm
by ddragas
Why array_combine doesn't combine two arrays in one 2dimensional?

Code: Select all

<?
if(isset($_POST['Submit']))
	{
		$id = array();
		$text_box_value = array();
		$niz = array();
		
		foreach ($_POST as $fieldName => $value)
		{
			if (($fieldName == 'kolicina'))
				{
					$text_box_value[] = $value;
				}
			if (($fieldName == 'id'))
				{
					$id[] = $value;
				}
			
		
		}
		
		$niz = array_combine($id, $text_box_value);
		
		print_r($niz);

	}
		else
	{
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"\">";


for($i=1; $i <= 10; $i++)
	{
		echo "<input type=\"hidden\" name=\"id\" value=\"$i\"/>
		<input name=\"kolicina\" type=\"text\"  value=\"$i\"/><br>";
	}
echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\" />";
echo "</form>";
}
?>

Posted: Fri Sep 29, 2006 5:14 pm
by Weirdan
start from turning your input fields into POST arrays (change from name='id' to name='id[]' and name='kolicina' to name='kolicina[]')

Posted: Fri Sep 29, 2006 5:20 pm
by ddragas
Thank you for reply

Of course :oops:



Sometimes U R blind with healthy eyes

regards ddragas

Posted: Fri Sep 29, 2006 6:03 pm
by ddragas
One more question

I'm having hard time with 2 dim arrays

haw to set variables from each array
to $id = first value from array,
and $amount = second value from array.

Ive tried to make it in 100 ways but it gives me nothing.

obviously I did not use the right way

Please help

regards ddragas
:oops:

Posted: Fri Sep 29, 2006 6:31 pm
by Weirdan
eh... I'm not certain if I understood you correctly, but you can try something like this

Code: Select all

foreach($arr as $val) {
  $id = $val[0];
  $amount = $val[1];
  // do something to id and amount
}