husslela03 Posted December 2, 2009 Share Posted December 2, 2009 Hello, I would like to compare two arrays and print the results on a page and be able to make a selection with radio boxes. Here is my code...specifically focusing on the for loops to create the arrays of the user names... filename='users.txt'; $fp=fopen($filename, 'r'); $file_contents=fread($fp, filesize($filename)); fclose($fp); $user_lines=explode("\n", $file_contents); foreach($user_lines as $line) { $user_info=explode(':', $line); $all_students=array_slice($user_info,0,0); } $file_open=rtrim($current_course); $file=".txt"; $full_file=$file_open.$file; //creates full file name to open $fp=fopen($full_file,'r'); //opens the file $course_contents=fread($fp,filesize($full_file)); $reg_stu_lines=explode("\n", $course_contents); foreach($reg_stu_lines as $stu_line) { $class_info=explode(':', $stu_line); $reg_students=array_slice($class_info,0,0); } $stu_to_add=array_diff($all_students,$reg_students); ?> then i was trying to print like this... <form action="add_student.php" method="get"> <?php for($i=1; $i<sizeof($stu_to_add);$i++) { $_SESSION['new_stu']=$data[$i]; echo '<input type=radio value="' .$_SESSION['new_stu']. '"name="new_student">' .$_SESSION['new_stu']. '</input><br>'; } echo '<input type=submit value="View Selected Course Info">'; ?> </form> Any help would be great! Thanks, jcjst21 Link to comment https://forums.phpfreaks.com/topic/183764-need-help-with-comparing-two-arrays-and-printing/ Share on other sites More sharing options...
zq29 Posted December 3, 2009 Share Posted December 3, 2009 You can compare arrays with array_diff() Link to comment https://forums.phpfreaks.com/topic/183764-need-help-with-comparing-two-arrays-and-printing/#findComment-970387 Share on other sites More sharing options...
husslela03 Posted December 3, 2009 Author Share Posted December 3, 2009 I did use array_diff() but it is not giving me any results... Link to comment https://forums.phpfreaks.com/topic/183764-need-help-with-comparing-two-arrays-and-printing/#findComment-970477 Share on other sites More sharing options...
husslela03 Posted December 3, 2009 Author Share Posted December 3, 2009 actually though, I get four results with the radio buttons, but I do not see any text.... Link to comment https://forums.phpfreaks.com/topic/183764-need-help-with-comparing-two-arrays-and-printing/#findComment-970478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.