Array Help?

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

Post Reply
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Array Help?

Post by JPlush76 »

Hey all, I'm trying to get my form to work as a multidemensional array. Basically I display a list of categories on a form and the user can update them all at the same time.

So I want to take 3 columns and turn them into one array element of a multidim. array

here is what I have so far but its not working right :(

Code: Select all

$arraytot = count($_POST['f_catid']);
	
		
	for($i=0; $i < $arraytot; $i++)
	{
		
		$newline = array(
							array(catid => $_POST['f_catid'],
								  catname => $_POST['f_catname'],
								  sortorder => $_POST['f_sort']),
						);
								  
		
		
}


 echo '<BR><BR><BR>'.print_r($newline);


its not creating the assoc array correctly. Anyone have any tips on how to do this? thanks!

p.s. here is the output I get from print_r. As you can see its not right

Array ( [0] => Array ( [catid] => Array ( [0] => 2801 [1] => 2802 [2] => [3] => [4] => ) [catname] => Array ( [0] => Video Tape [1] => Audio Tape [2] => [3] => [4] => ) [sortorder] => Array ( [0] => 10 [1] => 20 [2] => [3] => [4] => ) ) )
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Hi JPlush76,

Can you give us a more detailled description? What does your form look like?
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

actually I just got it! thanks for the quick reply though. The new code looks like this:

Code: Select all

<?php
for($i=0; $i < $arraytot; $i++)
	{
		if($_POST['f_catid'][$i] != '')
		{
			$newline[$i] = array(
								array('catid' => $_POST['f_catid'][$i],
								  'catname' => $_POST['f_catname'][$i],
								  'sortorder' => $_POST['f_sort'][$i]),
								);
		}
	}
?>
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Hi JPlush76,

I thought it would be the case 'cause I was wondering why you used a for loop...

Glad to have, maybe, prompted a solution for ya.
Post Reply