AL123 Posted December 27, 2009 Share Posted December 27, 2009 newbee Question: I can't get my info out of the array unless I use print_r(). echo or print just returns the word Array. Thanks - AL123 function pro_form() //process the form { echo "test, " . $_POST['test'] . " Done"; } function display_form($errors = '') //display the form { if($errors) { echo $errors; print_r($errors); } echo "<form method='post' action='$_SERVER[php_SELF]' > test: <input type='text' name='test'> <input type='submit' value='TEST'> <input type='hidden' name='submit_check' value='1'> </form>" ; } function validate_form() //pass errors to display_form { if(strlen($_POST['test']) < 3) { $errors[] = 'Whatever you post must be 3 chars long'; } if(strlen($_POST['test']) > { $errors[] = 'Whatever you post must be less than 8 chars long'; } return $errors; } if(array_key_exists('submit_check', $_POST)) { if($form_errors = validate_form()) { display_form($form_errors); } else { pro_form(); } } else { display_form(); } Link to comment https://forums.phpfreaks.com/topic/186407-array-info/ Share on other sites More sharing options...
premiso Posted December 27, 2009 Share Posted December 27, 2009 Use a foreach loop. if(is_array($errors)) { foreach ($errors as $error) echo $error; } That will loop through and display each item of the array. Link to comment https://forums.phpfreaks.com/topic/186407-array-info/#findComment-984366 Share on other sites More sharing options...
monkeytooth Posted December 27, 2009 Share Posted December 27, 2009 try echo "Array Value 1: " . $errors[0] . "<br />"; echo "Array Value 2: " . $errors[1] . "<br />"; echo "Array Value 3: " . $errors[2] . "<br />"; echo "Array Value 4: " . $errors[3] . "<br />"; echo "Array Value 5: " . $errors[4] . "<br />"; echo "Array Value 6: " . $errors[5] . "<br />"; echo "Array Value 7: " . $errors[6] . "<br />"; echo "Array Value 8: " . $errors[7] . "<br />"; thats bout the easiest way I can sum it up, as I can't think well right now under slept over worked ahh the life of a coder... Link to comment https://forums.phpfreaks.com/topic/186407-array-info/#findComment-984367 Share on other sites More sharing options...
AL123 Posted December 27, 2009 Author Share Posted December 27, 2009 Thanks a lot that worked perfectly. one day this will sink in! AL123. Link to comment https://forums.phpfreaks.com/topic/186407-array-info/#findComment-984370 Share on other sites More sharing options...
AL123 Posted December 27, 2009 Author Share Posted December 27, 2009 I used the loop AL123. Link to comment https://forums.phpfreaks.com/topic/186407-array-info/#findComment-984371 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.