1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php $insurees = [ 'u4937' => ['name' => 'Thomas Smythe', 'age' => 33], 'u1282' => ['name' => 'Gayle Runecor', 'age' => 25], 'u9275' => ['name' => 'Sara Pinnicle', 'age' => 57], 'u2078' => ['name' => 'Delilah Shock', 'age' => 41], ]; function insuree_age_sort($a, $b) { if ($a['age'] == $b['age']) { return 0; } return ($a['age'] > $b['age']) ? -1 : 1; } uasort($insurees, 'insuree_age_sort'); |
1 2 3 4 5 | <?php uasort($insurees, function ($a, $b) { if ($a['age'] == $b['age']) { return 0; } return ($a['age'] > $b['age']) ? -1 : 1; }); |
1 2 3 4 5 6 7 | <?php // Find only people over a certain age $minage = 40; $over = array_filter($insurees, function($a) use ($minage) { return ($a['age'] >= $minage); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?php $urls = [ 'training' => '/training', 'magazine' => '/magazine', 't-shirt' => '/swag/tshirts', ]; $current = $_SERVER['REQUEST_URI']; // May come from somewhere else // Helper for links, ignoring links if we are on that page: $link = function($name) use ($urls, $current) { if ($current == $urls[$name]) { return $name; } else { return "<a href=\"{$urls[$name]}\">{$name}</a>"; } }; ?> <p>Welcome to our website! Make sure to check out our <?= $link('training') ?> offerings, see the latest issue of our <?= $link('magazine'); ?>, and don't forget to check out our latest <?= $link('t-shirt') ?> designs as well.</p> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |