$asr_res = "первое";
if (preg_match('/(первое|первае|первуе)/', $asr_res)) {
$ress = 1;
}
SELECT
`t1`.*,
GROUP_CONCAT(`t3`.`name` SEPARATOR ', ') AS `role_group`
FROM
`user` AS `t1`
JOIN `user_role` AS `t2`
ON
`t1`.`id` = `t2`.`user_id`
JOIN `access_group` AS `t3`
ON
`t2`.`group_id` = `t3`.`id`
GROUP BY
`t1`.`id`
HAVING SUM(`group_id` IN('20', '24')) = 2
LIMIT 0, 20
$get_product = $db->prepare("SELECT * FROM products");
$get_product->execute();
// объявление массива
$product_data_array = [];
while ($product_data = $get_product->fetch()) {
// добавляем массив как елемент 2-мерного массива
$product_data_array[] = [
"name" => $product_data["name"],
"price" => $product_data["price"],
"status" => $product_data["status"],
];
}
var_dump($product_data_array);
$get_product = $db->prepare("SELECT * FROM products");
$get_product->execute();
$product_data_array = $get_product->fetchAll(PDO::FETCH_ASSOC);
var_dump($product_data_array);
<?php
$date = new DateTime();
$date->setTimestamp(1644537600000/1000);
echo $date->format('Y-m-d') . "\n";
<?php
$results = [
['order_id' => 'first', 'id'=>1],
['order_id' => 'second', 'id'=>4],
['order_id' => 'third', 'id'=>7]
];
$filtered = array_filter(
$results,
function($el) {
return $el['id'] != 4;
}
);
var_export($filtered);
<?php
$word = "Lorem ipsum dolor sit amet consectetur adipisicing elit.";
$wordarr = str_split($word);
$converted_letters = array_map(
function($i, $l) {
return $i % 2 == 0 ? strtoupper($l) : strtolower($l);
},
array_keys($wordarr),
$wordarr
);
echo implode($converted_letters);
CREATE TABLE Cities (
id int primary key auto_increment,
city varchar(64)
);
CREATE TABLE CityDistnce (
city1 int,
city2 int,
distance int,
foreign key (city1) references Cities(id),
foreign key (city2) references Cities(id),
index (city1, city2)
);
<?php
// Есть товар "Своя Кружка" 1"
$item = '"Своя Кружка" 1"';
// Мне нужно преобразовать в «Своя Кружка» 1'
$item_renamed = preg_replace('/"(\W+)" (\d+)"/m', "«$1» $2'", $item);
echo $item_renamed;
<?php
$str = 'Paris SG - Barcelona';
$teams = explode (' - ', $str);
var_export($teams);
array (
0 => 'Paris SG',
1 => 'Barcelona',
)
$result = mysqli_query($link, "SELECT acc_get_current_balance('@account_id') AS current_balance");
while ($row = mysqli_fetch_assoc($result)) {
echo "Current Balance : {$row['current_balance']} <br>";
}
<?php
require_once "mysitedb.php";
$query = "SELECT * FROM notes";
$select_note = mysqli_query($link, $query);
while ($note = mysqli_fetch_array($select_note)) {
echo $note["id"] . "<br>";
echo '<a href="comments.php?note=' . $note["id"] . '">' . $note["title"] . "</a>";
echo $note["created"], "<br>";
echo $note["article"], "<br>";
}
<?php
$arr =[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
$res = array_filter (
$arr,
function($el) { return ($el % 2 == 0); }
);
print_r($res);
<?php
$update = 'UPDATE `bes`
SET
`many` = IF (`many` >= :cena, `many` - :cena, `many`),
`activation` = IF (`many` >= :cena, 1, 0)
WHERE `activation` = 1';
$stmt = $pdo->prepare($update);
$stmt->execute([':cena'=>3]);
<?php
$query = "SELECT MAX(id) AS max FROM test";
$stmt = $pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$max_id = $row['max'];
$query = "SELECT * FROM test WHERE id >= ? LIMIT 1";
$stmt = $pdo->prepare($query);
$stmt->execute([rand(0, ($max_id-1))]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
if(!empty($masterSumm) && !empty($controlSumm)){
Возвращает false, если var существует и содержит непустое ненулевое значение или строку false, смотрите Преобразование в булев тип. В противном случае возвращает true.
SELECT user_id
FROM some_table
WHERE num IN (878, 925, 242)
GROUP BY user_id
HAVING COUNT(DISTINCT num) = 3 -- 3 количество вариантов
;
SELECT some_table.user_id
FROM some_table
JOIN some_table st1 ON st1.user_id = some_table.user_id AND st1.num = 925
JOIN some_table st2 ON st2.user_id = some_table.user_id AND st2.num = 242
WHERE some_table.num = 878
;
SELECT user_id, GROUP_CONCAT(DISTINCT num ORDER BY num)
FROM some_table
WHERE num IN (878,925,242)
GROUP BY user_id
HAVING GROUP_CONCAT(DISTINCT num) = '242,878,925'
;
// найдем ключи с равными значениями
$equal_keys = array_keys(array_intersect_assoc(...$array));
foreach ($array as $k=>$val) {
// в цикле отфильтруем лишнее
$array[$k] = array_filter(
$val,
function ($key) use ($equal_keys) {
return !in_array($key, $equal_keys);
},
ARRAY_FILTER_USE_KEY
);
}