garry27 Posted September 8, 2008 Share Posted September 8, 2008 I've been trying to create a loop for the following array but I keep getting errors. $formOutputData[] = array(array('name'=>'username', 'longName'=>'Username', 'maxLen'=>20, 'isRequired'=>true ), array('name'=>'forename', 'longName'=>'Forename', 'maxLen'=>15, 'isRequired'=>true ), array('name'=>'surname', 'longName'=>'Surname', 'maxLen'=>20, 'isRequired'=>true ), array('name'=>'town', 'longName'=>'Town', 'maxLen'=>20, 'isRequired'=>false ), array('name'=>'userEmail', 'longName'=>'Email Address', 'maxLen'=>40, 'isRequired'=>true ), array('name'=>'userPassword', 'longName'=>'Password', 'maxLen'=>20, 'isRequired'=>true ), array('name'=>'userPassword2', 'longName'=>'Password', 'maxLen'=>10000, 'isRequired'=>false ) ); here is the loop I'm using (pretty much out of the book i'm using) but I get: Warning: Variable passed to each() is not an array or object in /home/gigaddic/public_html/classes/user_input.php on line 96 function getNameValues($formOutputData) //get expected key and value params { $expected = array(); $num = count($formOutputData); for ( $row=0; $row < 6; $row++ ) { while (list($key,$value) = each($formOutputData[$row])) { if($value == 'name' && $_POST[$value] ) { $expected[$key] = $value ; } } } return $expected; } Please advise me Link to comment https://forums.phpfreaks.com/topic/123332-loops-and-multicolumn-arrays/ Share on other sites More sharing options...
garry27 Posted September 8, 2008 Author Share Posted September 8, 2008 please help Link to comment https://forums.phpfreaks.com/topic/123332-loops-and-multicolumn-arrays/#findComment-637046 Share on other sites More sharing options...
garry27 Posted September 9, 2008 Author Share Posted September 9, 2008 hello?!? Link to comment https://forums.phpfreaks.com/topic/123332-loops-and-multicolumn-arrays/#findComment-637472 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2008 Share Posted September 9, 2008 apparently, $formOutputData[$row] is not an array. print_r($formOutputData[$row]) and/or $formOutputData to see what it is. Link to comment https://forums.phpfreaks.com/topic/123332-loops-and-multicolumn-arrays/#findComment-637483 Share on other sites More sharing options...
lanmonkey Posted September 9, 2008 Share Posted September 9, 2008 Right... here is your problem: when you define your array you put: $formOutputData[] = array(array(... blah blah blah this should be : $formOutputData = array(array(... blah blah blah so... $stuff[] = 'some stuff'; ..will create a valid single dimension array: $stuff[] = array(0=>"some other stuff"); Creates an array within an array. You have actually created an array thats 3 levels deep but your loop is designed to handle an array thats 2 levels deep. Link to comment https://forums.phpfreaks.com/topic/123332-loops-and-multicolumn-arrays/#findComment-637496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.