$db->beginTransaction();
if ($query->execute()) {
if ($query->execute()) {
$db->commit();
return true;
}
}
$db->rollback();
return false;
type Client struct {
ID int // Идентификатор юзера
Nickname string // Никнейм клиента
Conn *websocket.Conn // Сокет клиента
}
{"to" : "nickname", "message" : "hello"}
<?php
function parse($text) {
$lines = explode("\n", $text);
$result = [];
$switched = false;
$i = 0;
foreach($lines as $line) {
// Add item
if (count($matches = preg_split('/->/', $line, -1, PREG_SPLIT_NO_EMPTY)) == 2) {
if (!isset($result[$i])) {
$result[$i] = [];
}
$result[$i][$matches[0]] = $matches[1];
$switched = false;
} else if (!$switched) {
$i++;
$switched = true;
}
}
return $result;
}
$text = "
_wpcf7->104
_wpcf7_version->4.7
_wpcf7_locale->ru_RU
_wpcf7_unit_tag->wpcf7-f104-p157-o3
_wpnonce->2b8273a977
your-name->Krisan Lang
menu-968->Firma
text-463->Best OÜ
tel-179->58813468606
your-email->kridgfgstjan@best5apartments.ee
November 29, 2017, 18:07:14
_wpcf7->104
_wpcf7_version->4.7
_wpcf7_locale->ru_RU
_wpcf7_unit_tag->wpcf7-f104-p67-o1
_wpnonce->2b8273a977
your-name->Liis dfValma
menu-968->Eraisik
text-463->
tel-179->5396643367
your-email->liisvalma2401@gmail.com
";
print_r(parse($text));
/<([a-z]+)>(?<!<p>).+(?!(?:<\/p>|<\/\1>))\{PAGEBREAK\}.+<\/\1>/
preg_replace("/(?P<start><([a-z]+)>(?<!<p>).+(?!(?:<\/p>|<\/\2>)))\{PAGEBREAK\}(?P<end>.+<\/\2>)/", "\1 \3 {PAGEBREAK}", $input_lines);
<?php
$array = [
[
'player_id' => 1,
'count_goals' => 1
],
[
'player_id' => 1,
'count_goals' => 1
],
[
'player_id' => 1,
'count_goals' => 1
],
[
'player_id' => 1,
'count_goals' => 1
],
];
function filter($array)
{
$result = [];
foreach($array as $key => $value) {
if (array_key_exists($value['player_id'], $result)) {
$result[$value['player_id']]['count_goals'] += $value['count_goals'];
} else {
$result[$value['player_id']] = $value;
}
}
return array_values($result);
}
print_r(filter($array));
<?php
$a = [
'color' => ['red', 'blue', 'orange'],
'size' => ['10-12', '12-14', '13-13'],
'somekey' => ['val1', 'val2', 'val3'],
];
function addValue(&$arr, $key, $val)
{
if (!count($arr)) {
$arr[] = [$key => $val];
return;
}
foreach($arr as $num => $values) {
$arr[$num][$key] = $val;
}
}
$b = [];
foreach($a as $key => $values) {
$copyB = $b;
$newB = [];
foreach($values as $value) {
$currentB = $copyB;
addValue($currentB, $key, $value);
$newB = array_merge($newB, $currentB);
}
$b = $newB;
}
print_r($b);
SELECT DISTINCT code_medication, MIN(price) FROM tailings t GROUP BY code_medication LIMIT 50;
Product::find()
->distinct()
->select('code, MIN(price)')
->from('product')
->groupBy('code');
SELECT * FROM tailings t WHERE t.price = (SELECT MIN(t2.price) FROM tailings t2 WHERE t2.code_medication = t.code_medication) GROUP BY t.code_medication;
$subQuery = (new Query())->select('MIN(t2.price)')->from('tailings t2')->where('t2.code_medication = t.code_medication');
$query = Product::find()->from('tailings t')->where(['t.price' => $subQuery])->groupBy('t.code_medication');
$countQuery = clone $query;
$pages = new Pagination([
'totalCount' => $countQuery->count(),
'pageSize' => 15,
'forcePageParam' => false,
'pageSizeParam' => false,
]);
$products = $query->offset($pages->offset)->limit($pages->limit)->all();
['birth_date', 'date', 'timestampAttribute' => 'birth_date', 'timestampAttributeFormat' => 'php:Y-m-d'],
['death_date', 'date', 'timestampAttribute' => 'death_date', 'timestampAttributeFormat' => 'php:Y-m-d'],
['death_date', function($attribute, $params) {
if (\DateTime::createFromFormat("Y-m-d", $this->{$attribute})->getTimestamp() < \DateTime::createFromFormat("Y-m-d", $this->birth_date)->getTimestamp()) {
$this->addError($attribute, 'Дата смерти не может быть меньше даты рождения.');
}
}]
if (\DateTime::createFromFormat("Y-m-d", $this->death_date)->getTimestamp() < \DateTime::createFromFormat("Y-m-d", $this->birth_date)->getTimestamp()) {
$this->addError($attribute, 'Дата смерти не может быть меньше даты рождения.');
}
$aq = Users::find()->distinct()->alias('u');
if ($this->role !== null) {
$aq->leftJoin('auth_assignment a', 'a.user_id = u.id AND a.item_name = :role', [':role' => $this->role]);
$aq->where("a.user_id IS NOT NULL");
}
package main
import "fmt"
// Структура для сохранения результатов
type concurrences struct {
number int
count int
}
// Функция для инкремента элемента
func inc(num int) {
changed := false
for i:=0; i < len(conc); i++ {
if conc[i].number == num {
conc[i].count++
changed = true
break
}
}
if !changed {
conc = append(conc, concurrences{num, 1})
}
}
var conc = []concurrences{}
// Массив с элементами
var numbers = []int{1, 2, 6, 2, 1, 9, 0, 3}
func main() {
for i:=0; i < len(numbers); i++ {
inc(numbers[i])
}
// Отдаст элемент и кол-во его вхождений в массив
// [{1 2} {2 2} {6 1} {9 1} {0 1} {3 1}]
fmt.Println(conc)
// N - кол-во вхождений элемента в массив
N := 2
// Выводим все элементы которые есть в массиве N раз
for i:=0; i < len(conc); i++ {
if conc[i].count == N {
fmt.Println(conc[i].number)
}
}
}
// Steam api key
SteamPlayer::$API_KEY = 'api key';
// Массив идентификаторов стима
$steamIDs = [
'xxxxxxxxxxxxxxxxxxxxx',
'xxxxxxxxxxxxxxxxxxxxx',
'xxxxxxxxxxxxxxxxxxxxx'
];
// Отдает коллекцию объектов SteamPlayer
$SteamPlayerCollection = SteamPlayer::Create($steamIDs);
// Получаем массив инстансов SteamPlayer[] и выводим ссылку на большой аватара у каждого
foreach($SteamPlayerCollection->get() as $player){
echo $player->avatar(SteamPlayer::AVATAR_LARGE);
}
$message = $status = null;
if (Yii::$app->request->post()) {
if ($model->save()) {
$status = 'success';
$message = 'Спасибо операция окончена';
} else {
$status = 'error';
$message = 'Извините произошла ошибка';
}
}
$this->render('html', [
'model' => $model,
'status' => $status,
'message' => $message,
]);
<?php if ($status !== null && $message !== null): ?>
<div class="alert alert-<?=$status?>">
<strong><?=$status?>!</strong> <?=$message?>
</div>
<?php endif; ?>
.......
.......