Jump to content

need help with comparing two arrays and printing


husslela03

Recommended Posts

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.