PHP
- 9 ответов
- 0 вопросов
8
Вклад в тег
<?php
$arr = range(1, 200);
$arr[50] = 0;
$arr[100] = 0;
$arr[150] = 0;
$arr[200] = 0;
$arr[99] = 9999;
$preparedArray = prepareArray($arr);
$sortedArray = sortArray($preparedArray);
showArray($sortedArray);
function prepareArray(array $arr)
{
$result = [];
$counter = 0;
$sum = 0;
foreach ($arr as $key => $value) {
if ($arr[$key] != 0) {
$counter++;
$sum += $value;
} else {
if ($counter != 0 and $sum / $counter > 20) {
$result[] = [
'sum' => $sum,
'counter' => $counter,
'key' => $key,
'intval' => intval($key / 30 / 60),
'proc' => $key / 30 % 60,
];
}
$counter = 0;
$sum = 0;
}
}
return $result;
}
function sortArray(array $arr)
{
usort($arr, function ($elem1, $elem2) {
return $elem1['sum'] <=> $elem2['sum'];
});
return $arr;
}
function showArray(array $arr)
{
foreach ($arr as $elem) {
echo $elem['sum'] . '/' . $elem['counter'] . ' (' . $elem['key'] . ') ' . $elem['intval'] . ':' . $elem['proc'] . "<br>";
}
}
<?php
use Illuminate\Database\Seeder;
use App\Models\Group;
use App\Models\Permission;
class GroupsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$group = $this->seedGroup([
'name' => 'Administrator',
]);
$group->permissions()->sync(
Permission::all()->pluck('id')->toArray()
);
}
private function seedGroup(array $data)
{
$group = new Group([
'name' => $data['name'],
]);
$group->save();
return $group;
}
}
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(GroupsTableSeeder::class);
}
}
<html>
<body>
<select name="users" id="users">
<option value="User 1">User 1</option>
<option value="User 2">User 2</option>
<option value="User 3">User 3</option>
<option value="User 4">User 4</option>
</select>
<script
src="https://code.jquery.com/jquery-3.4.0.slim.min.js"
integrity="sha256-ZaXnYkHGqIhqTbJ6MB4l9Frs/r7U4jlx7ir8PJYBqbI="
crossorigin="anonymous"></script>
<script>
$(document).ready(function() {
$('#users').change(function() {
document.location.href = "/search.php?query=" + $('#users option:selected').val();
});
});
</script>
</body>
</html>
<html>
<body>
<a href="#anchor1">Anchor to footer</a>
<a href="#anchor2">Anchor to a</a>
<a href="#anchor3">Anchor to div</a>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<footer name="anchor1"></footer>
<a name="anchor2"></a>
<div name="anchor3"></div>
</body>
</html>