printf('b: %b
c: %c
d: %d f: %f', 80,80, 80, 80);
echo '
';
printf('%0.2f
%+d
%0.2f
', 8, 8, 1235.456);

printf('the cost of %d %s at $%0.2f each is $%0.2f.', 4, 'brooms', 8.50, (4*8.50));

echo '
';
$tax = 30;
printf('The tax rate is %0.2f%%', $tax);





Sorting Multidimensional Arrays


$db = mysqli_connect('192.168.31.172', 'root', 'root', 'phpadvanced');
mysqli_query($db, "set names utf8");

if(!empty($_POST['task'])) {
$parent_id = 0;
if(isset($_POST['parent_id']) && filter_var($_POST['parent_id'], FILTER_VALIDATE_INT, ['min_range' => 1])) {
$parent_id = $_POST['parent_id'];
}

$q = sprintf("INSERT INTO tasks (parent_id, task) VALUES (%d, '%s')", $parent_id, mysqli_real_escape_string($db, strip_tags($_POST['task'])));
$r = mysqli_query($db, $q);

if(mysqli_affected_rows($db) == 1) {
    echo '

任务添加成功

'; } else { echo '

任务添加失败

'; }

}
?>



添加一个任务

任务:


上级任务:

// 对任务的父id进行排序
function parent_sort($x, $y) {
return ($x['parent_id'] > $y['parent_id']);
}
usort($tasks, 'parent_sort');
echo '

当前的任务列表

    ';
    foreach ($tasks as $task) {
    echo "
  • {$task['task']}
  • \n";
    }
    echo '
';
?>


龙华大道1号http://www.kinghill.cn/LongHuaDaDao1Hao/index.html