$items = [
'item_a' => ['require' => ['item_b']],
'item_b' => ['require' => ['item_с']],
'item_c' => ['require' => ['item_a']],
];
foreach (array_keys($items) as $key) {
$items[$key]['name'] = $key;
}
uasort($items, function($a, $b) {
return (in_array($b['name'], $a['require']) || empty($b['require']));
});
/**
* @param array $items
* @return bool
*/
function search_cycle($items)
{
$search = function(array $path) use ($items, &$search)
{
$count = count($path);
$first = $path[0];
$last = $path[$count - 1];
if ($count > 1 && in_array($last, array_slice($path, 0, $count - 1))) {
return true;
}
foreach ($items[$last]['require'] as $key) {
if ($search(array_merge($path, [$key]))) {
return true;
}
}
return false;
};
foreach ($items as $key => $data) {
if ($search([$key])) {
return true;
}
}
return false;
}
list($a, $b) = preg_split('/(?=\/[^\/]+$)/', '/текст/текст текст/нетекст/текст');
class B extends A
{
public function __construct()
{
echo 'In B';
Prnt::__construct();
}
}
class B extends A
{
public function __construct()
{
echo 'In B';
$reflection = new ReflectionClass(self::class);
$parent = $reflection->getParentClass();
while ($parent->getParentClass()) {
$parent = $parent->getParentClass();
}
$class = $parent->getName();
$class::__construct();
}
}
$n = 3;
$m = 2;
for ($i = $n; ; $i = ($i < 7 ? $i + 1 : 1)){
echo $i . ' ';
if ($i == $m) break;
}
$n = 3;
$m = 2;
$i = $n - 1;
do {
$d = $i % 7 + 1;
echo $d . ' ';
$i++;
} while ($d != $m);
$array = [1, 2, 3, 4, 5, 6, 7];
$n = 3;
$m = 2;
$i = array_search($n, $array);
$result = array_merge(array_slice($array, $i), array_slice($array, 0, $i));
<table>
<?php foreach (array_chunk($arr, 9) as $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?php echo $value; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
function slugify($string) {
$translit = "Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();";
$string = transliterator_transliterate($translit, $string);
$string = preg_replace('/[-\s]+/', '-', $string);
return trim($string, '-');
}
echo slugify("Я люблю PHP!");
$transaction = $connection->beginTransaction();
try {
// Этап 1
$dbAdapter->insert($data);
// Этап 2
$mailAdapter->sendMessage();
// ...
$transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
throw $e;
}