if ($result = $db->query('SELECT id, name, price FROM product '
. 'WHERE status = "1"'
. 'ORDER BY id DESC '
. 'LIMIT ' . $count)) {
// твой код
} else {
else echo($db->error);
}
[
['alex', '111111'],
['alex', 2222222],
...
]
[
'111111' => ['alex', 'john'],
'222222' => ['alex']
...
]
$data = [
'alex' => [
"1111111",
"2222222",
"1726354"
],
'john' => [
"1111111",
"3333333",
"7162534"
],
'michel' => [
"1111111",
"453453453",
"3333333"
]
] ;
$res = [];
foreach ($data as $name => $phones) {
foreach($phones as $phone) {
if (!array_key_exists($phone, $res)) {
$res[$phone] = [];
}
$res[$phone][] = $name;
}
}
print_r($res)
Array
(
[1111111] => Array
(
[0] => alex
[1] => john
[2] => michel
)
[2222222] => Array
(
[0] => alex
)
[1726354] => Array
(
[0] => alex
)
[3333333] => Array
(
[0] => john
[1] => michel
)
[7162534] => Array
(
[0] => john
)
[453453453] => Array
(
[0] => michel
)
)
$arr = [0 => 'a', 1 => 'b', 2 => 'c'];
$res = [];
for ($i = 1; $i < pow(2, count($arr)); $i++ ) {
$bin = decbin($i);
$case = "";
foreach(str_split(strrev($bin)) as $ind => $symb) if ($symb == "1") $case .= $arr[$ind];
$res[] = $case;
}
echo implode(", ", $res); // a, b, ab, c, ac, bc, abc
$sku == strpos($sku, 'https')
$sku = isset($_GET['sku']) ? str_replace(" ", "", $_GET['sku']) : null;
if (is_numeric($sku)) { // если начало с цифры
$filter = ['idProduct', $sku, true];
} elseif (substr($sku, 0, 5) == 'https') { // если начало с https
$beforeBlockMain = strstr($sku, '?block_main', true) || $sku;
$filter = ['linkProduct', $sku . ($sku_new ? '/' : ''), false];
} elseif ($sku) {
$filter = ['name', "%" . $sku . "%", true];
}
if ($filter) {
$attrName = $filter[0];
$value = $filter[1];
$operator = $value[0] == "%" ? " LIKE " : " = ";
$limit = $filter[2];
$sql = "SELECT * FROM products WHERE " . $attrName . $operator . $value . ($limit ? " LIMIT 0,1" : "");
}
$s1 = 'Lorem {val1} dolor sit {val2}, consectetur adipisicing {val3}.';
$s2 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.';
$patterns = [];
$pattern2 = preg_replace_callback('|\{([a-z0-9]+)\}|', function($m) use (&$patterns) {
$patterns[] = $m[1];
return '(.*)';
}, $s1);
preg_match('|' . $pattern2 . '|', $s2, $matches);
$res = array_combine($patterns, array_slice($matches, 1));
var_dump($res);