foreach loop error

A

Anonymous

Guest
I'm making a school survey, and my design is very complex. I take in values and hidden values and make two multidimensional arrays. and take any of four actions: add question, delete question, add answer, delete answer. I have a hidden value that in one line of numbers and signs. I send it through loop it makes a multidimensional array which is the guild line for how many questions and how many answers per question. No problem. The problem I'm having is that when I building the array (after one of the actions is completed) back into a string for a hidden value. (Impolding a multidimensional array into a string) It is giving me an error:

Warning: Invalid argument supplied for foreach() in /survey/create.php on line 75

Here is my code I been tring to get to work:
Code:
	foreach ($numa_list as $numa_item) {
		$numa_list['.'] = implode("--", $numa_item);
	}
	$answers = implode("---", $numa_list);
	echo $answers;
As you can see I'm tring to see my results when it's done, but I keep geting this error when my loop is correct! :)help:) If I can't even get my loop to work I can't finish debuging my impolde functions. Can anyone help me will these probelms!
 
Warning: Invalid argument supplied for foreach() in /survey/create.php on line 75
check your $numa_list variable if it is an array.
 
Yes it is. Here is my code that explodes the string into the array $numa_list:
Code:
		//Grab the number off answers for current question
		$numa_list = array();
		$array = explode('---',$HTTP_POST_VARS['numa']);
		foreach ($array as $value) {
			 if (!empty($value)) {
				  list($list, $list2) = explode('--',$value);
				  $numa_list .= array($list => $list2);
			 }
		}
 
why don't you change your separators,
keep one like @@@@ and other like ####

the hyphens being the same separator could be creating problems
 
Thats for the idea. I think I figure my problem out. I was building my array wrong. When I built my array from the hidden values, I treated it like a string a used .= to add an array item (you can see this in my last post.) So can you help me with this. I need to know how to add array items to the end of a multidimensional array (as you see in my last post)
 
you can simply push values to array using array_push
or else you can add to that array by

Code:
$arry['someindex'][] = $newvalue;
 
Back
Top