The link @Gordon sent me to, helped get me the answer.
This is my new working code.
<?php
$app = $_POST['app'];
if (isset($_POST['app'])) {
$dir ="../apps/" . $app;
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) {
$file->isDir() ? rmdir($file) : unlink($file);
}
rmdir($dir);
}
?>