PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ddragas
Forum Contributor
Posts: 445 Joined: Sun Apr 18, 2004 4:01 pm
Post
by ddragas » Fri Sep 29, 2006 4:46 pm
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>";
}
?>
Last edited by
ddragas on Fri Sep 29, 2006 5:56 pm, edited 2 times in total.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Sep 29, 2006 5:14 pm
start from turning your input fields into POST arrays (change from name='id' to name='id[]' and name='kolicina' to name='kolicina[]')
ddragas
Forum Contributor
Posts: 445 Joined: Sun Apr 18, 2004 4:01 pm
Post
by ddragas » Fri Sep 29, 2006 5:20 pm
Thank you for reply
Of course
Sometimes U R blind with healthy eyes
regards ddragas
ddragas
Forum Contributor
Posts: 445 Joined: Sun Apr 18, 2004 4:01 pm
Post
by ddragas » Fri Sep 29, 2006 6:03 pm
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
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Fri Sep 29, 2006 6:31 pm
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
}