везде делать проверку на существование такого элемента с индексом?
$className = 'Home';
$classFileName = __DIR__ . '/home.php';
$template = <<<'EOD'
<?php
class <<CLASS_NAME>> {
function __construct(public $name, public $age){}
function show_values(){
echo "$this->name <br> $this->age <br><br>";
}
}
EOD;
$classCode = str_replace('<<CLASS_NAME>>', $className, $template);
file_put_contents($classFileName, $classCode);
function getSetAge(?int $age=null): int
{
if (!is_null($age)) {
$this->age = $age;
}
return $this->age;
}}
$fileName = '1.csv';
$lineLength = 1024;
$linesCount = 15;
$handle = fopen($fileName, "r");
$fileSize = filesize($fileName);
$data = [];
if ($fileSize !== 0) {
for ($num = 1; $num <= $linesCount; $num++) {
$rand = rand(0, $fileSize);
fseek($handle, $rand);
$firstPointer = null;
do {
fgets($handle); // trash
$pointer = ftell($handle);
if ($pointer === $fileSize) {
fseek($handle, 0);
$pointer = 0;
}
if ($pointer === $firstPointer) { // loop detect
continue 2;
}
$firstPointer = $firstPointer ?? $pointer;
} while (array_key_exists($pointer, $data));
$data[$pointer] = fgets($handle);
}
}
ksort($data); // sort by order in file
var_dump($data);
... выглядит примерно так: 01
То есть 0 не убирается, как то исправить?
echo sprintf('%02d',1);
abstract protected function mapToArray(Model $object ): array;
...
class User extends Model
str_replace(['*','x'],'R','2*10*30 2x10x30');
preg_filter('/(\d+)[*x](\d+)[*x](\d+)/', '${1}R${2}R${3}', '2*10*30 2x10x30')