$file = 'путь';
$image = imagecreatefromstring(file_get_contents($file));
$array = array_map('realpath', glob('*.*'));
echo '<pre>' . print_r($array, true) . '</pre>';
$resource = imagecreatefromstring(file_get_contents($array[1]));
echo get_resource_type($resource);
echo '<form action="" method="post">
<input type="text" name="name" />
<input type="submit" name="submit" />
</form>';
$data = 'data.dat';
if (!file_exists($data)) {
touch($data);
}
if (isset($_POST['submit'])) {
$array = file($data, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$int = count($array) ? (int)end($array) : 0;
$array[] = ++$int . ':' . ($_POST['name'] ?? 'Test') . PHP_EOL;
$fp = fopen($data, 'r+b');
if (flock($fp, LOCK_EX)) {
ftruncate($fp, 0);
fwrite($fp, implode(PHP_EOL, $array));
fflush($fp);
flock($fp, LOCK_UN);
}
}
$array = [
'127.0.0.1',
'127.0.0.2',
'127.0.0.3',
'127.0.0.4',
'127.0.0.5',
'127.0.0.6',
'127.0.0.7',
'127.0.0.8',
'127.0.0.9',
];
$result = []; // результат
$len = 4; // длинна первого массива (менять для экспериментов)
$c = ceil(count($array) / $len) - 1; // количество итераций
$result[] = array_slice($array, 0, $len); // первый срез
$offset = $len - 1; // смещение для первой итерации
for (++$len, $j = 0, $i = 0; $i < $c; $i++, $offset += $len - 1, $j += $len) {
$result[] = array_slice($array, $offset, $len);
}
echo '<pre>' . print_r($result, true) . '</pre>';
function sizeofdir($dir) {
$dir = realpath($dir);
$fileSPLObjects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST);
$dirs = 0;
$files = 0;
$dirsize = 0;
foreach( $fileSPLObjects as $fullFileName => $fileSPLObject ) {
if ($fileSPLObject->isDir()) {
$dirs++;
} elseif ($fileSPLObject->isFile()) {
$files++;
$dirsize += $fileSPLObject->getSize();
}
}
return $dirs . ' - Dir(s) , Total: ' . $files . ' file(s) , ' . file_size($dirsize);
}
function file_size($size)
{
$filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes';
}
$count = $json['pages'];
$dept = [];
for($d = 0; $d < $count; $d++) {
$dept[] = count($json['pages][$d]['attribute'];
}
$max = max($dept);
echo '<table><tr>';
for ($i = 0; $i < $count; $i++) {
echo '<th>' . $json['pages][$i]['name'] . '</th>';
} // заголовок
echo '</tr>';
while(++$x < $max) {
echo '<tr>';
for($k = 0; $k < $count; $k++) {
echo '<td>' . ($json['pages'][$k]['attribute][$x] ?? '') . '</td>';
}
echo '</tr>';
}
echo '</table>';
class Comparator
{
private $value;
private $compareValue;
public function __construct($value, $compareValue = null)
{
$this->value = $value;
$this->compareValue = $compareValue;
// for float comparison
if (is_numeric($this->value) && is_numeric($this->compareValue)) {
$this->value *= 100;
$this->compareValue *= 100;
}
}
public function equals(): bool
{
return $this->value === $this->compareValue;
}
public function notEquals(): bool
{
return $this->value !== $this->compareValue;
}
public function greaterThan(): bool
{
return $this->value > $this->compareValue;
}
public function greaterThanOrEqual(): bool
{
return $this->value >= $this->compareValue;
}
public function lessThan(): bool
{
return $this->value < $this->compareValue;
}
public function lessThanOrEqual(): bool
{
return $this->value <= $this->compareValue;
}
public function isNull(): bool
{
return $this->value === null;
}
public function isNotNull(): bool
{
return $this->value !== null;
}
public function isTrue(): bool
{
return $this->value === true;
}
public function isFalse(): bool
{
return !$this->isTrue();
}
public function and(): bool
{
return $this->value && $this->compareValue;
}
public function or(): bool
{
return $this->value || $this->compareValue;
}
}
/*
"{value} >= 5 || {value} < 6.7",
"{value} !== 'test' && {value} === true'
*/
$compare = new Comparator(10, 5);
$c1 = $compare->greaterThanOrEqual();
$compare = new Comparator(10.3, 6.7);
$c2 = $compare->lessThan();
var_dump($c1);
var_dump($c2);
$compare = new Comparator($c1, $c2);
$c3 = $compare->or();
var_dump($c3);