Help with nested foreach loops
I am trying to ultimately find files in a directory that are no longer being used and delete them. I am using a field in my database to match against the filenames; they are the same.

The outer loop is for the database values and the inner loop is for the files in the directory. I'm using an if stmt inside the inner loop but I am getting files showing up in the output that should not be there. What am I doing wrong?

If I have a file in my directory and no matching database value, I want to delete the file.

                    foreach( $ds as $id ){
                        foreach( $out as $file ){
                            if( $file != $id['patient_id'] ){
                                echo $id['patient_id'];
                            }
                        }
                    }
Help with nested foreach loops
===

I am trying to ultimately find files in a directory that are no longer being used and delete them. I am using a field in my database to match against the filenames; they are the same.

The outer loop is for the database values and the inner loop is for the files in the directory. I'm using an if stmt inside the inner loop but I am getting files showing up in the output that should not be there. What am I doing wrong?

If I have a file in my directory and no matching database value, I want to delete the file.

                    foreach( $ds as $id ){
                        foreach( $out as $file ){
                            if( $file != $id['patient_id'] ){
                                echo $id['patient_id'];
                            }
                        }
                    }