$data = ['row1', 'row2', 'row3', 'row4', 'row5'];
$countToDelete = 3;
$i = 0;
foreach ($data as $index => $value) {
unset($data[$index]);
if ($i >= $countToDelete - 1) {
break;
}
$i++;
}
var_dump($data);
/*
array(2) {
[3]=>
string(4) "row4"
[4]=>
string(4) "row5"
}
*/
$data = ['row1', 'row2', 'row3', 'row4', 'row5'];
$countToDelete = 3;
$filtered = array_filter($data, function ($value) use (&$countToDelete) {
return $countToDelete-- <= 0;
});
var_dump($filtered);
/*
array(2) {
[3]=>
string(4) "row4"
[4]=>
string(4) "row5"
}
*/
$data = [
'Hi' => 1,
'D' => [
'type' => 'xz',
'anything' => $any2
],
'Any' => [
[
'type' => 'xz',
'anything' => $any2
]
],
'Anything' => [],
'Minus' => [
'Content',
'Content'
],
'Block' => [
'dog' => "Hello-$hello2",
'cat' => '',
'parrot' => ''
]
];
if ($content != $content2) {
$data['Anything'][] = [
'block1' => $block2
];
}
$response = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
// $response = base64_encode($response);
echo $response;
function code(string $letter = 'P', int $count = 8, string $delimiter = '-'): string
{
$code = $letter . $delimiter . mt_rand(1, 9);
for ($i = 0; $i < $count - 1; $i++) {
$code .= mt_rand(0, 9);
}
return $code;
}
if (file_exists('myscript.running')) {
echo 'Скрипт уже работает!', PHP_EOL;
return;
}
touch('myscript.running');
// Тут ваш код
UPDATE `TableName` SET `cnt` = 0 WHERE `id` IN (1314, 24414, 12121, 1141, 3453)