foreach ($items as $itemIndex=>$item) {
foreach($item['stocks'] as $stockIndex=>$stock) {
if ($stock['type'] === "fbo") {
unset($items[$itemIndex]['stocks'][$stockIndex]);
$items[$itemIndex]['stocks'] = array_values($items[$itemIndex]['stocks']);
}
}
}
$salePrice = $price - ($price/100*3);
<?= $salePrice ?>
function findPair(string $text, array $words, int $range=5) {
$rows = explode(PHP_EOL, $text);
$numberLength = 5;
$pair = null;
$isNumberFound = false;
foreach ($words as $word) {
foreach ($rows as $row) {
$wordPos = strpos($row, $word);
$isWordInRow = $wordPos !== false;
if (!$isWordInRow) {
continue;
}
/* Going backwards first */
$backwardSearchStart = $wordPos-1;
$backwardSearchEnd = $backwardSearchStart - $range;
for ($symbolPos=$backwardSearchStart; $symbolPos>$backwardSearchEnd; $symbolPos--) {
// Stop backward search if we are in the very beginning of the row
if ($symbolPos <= 0) {
break;
}
$symbol = substr($row, $symbolPos, 1);
if (is_numeric($symbol)) {
$lastNumberPos = $symbolPos - $numberLength;
$digits = [];
for ($digitPos=$symbolPos; $digitPos>$lastNumberPos; $digitPos--) {
$digit = substr($row, $digitPos, 1);
if (is_numeric($digit)) {
$digits[] = $digit;
} else {
break;
}
}
$isNumberFound = count($digits) === $numberLength;
if ($isNumberFound) {
$number = implode(array_reverse($digits));
$pair = [$word, $number];
break;
}
}
}
if ($isNumberFound) {
return $pair;
}
/* Forward search */
$forwardSearchStart = $wordPos+1+strlen($word);
$forwardSearchEnd = $forwardSearchStart + $range;
for ($symbolPos=$forwardSearchStart; $symbolPos<$forwardSearchEnd; $symbolPos++) {
$symbol = substr($row, $symbolPos, 1);
if (is_numeric($symbol)) {
$lastNumberPos = $symbolPos + $numberLength;
$digits = [];
for ($digitPos=$symbolPos; $digitPos<$lastNumberPos; $digitPos++) {
$digit = substr($row, $digitPos, 1);
if (is_numeric($digit)) {
$digits[] = $digit;
} else {
break;
}
}
$isNumberFound = count($digits) === $numberLength;
if ($isNumberFound) {
$number = implode($digits);
$pair = [$word, $number];
break;
}
}
}
if ($isNumberFound) {
return $pair;
}
}
}
return $pair;
}
$words = ["apple", "word", "new"];
$text = <<<TEXT
what, 10924
59012, test
VT 92918
word, 18913
site 85719
12345 Wisconsin
TEXT;
$pair = findPair($text, $words);
/* Result:
array(2) {
[0]=>
string(4) "word"
[1]=>
string(5) "18913"
}
*/
SELECT
## product_id
CASE
WHEN COUNT(`products`.`product_id`)=1 THEN ANY_VALUE(`products`.`product_id`)
ELSE (
SELECT
`product_id`
FROM
`products` AS `product_id_sub`
WHERE 1
AND `product_id_sub`.`group_id`=`products`.`group_id`
AND `product_id_sub`.`quantity` > `product_id_sub`.`minimum`
ORDER BY
`product_id_sub`.`minimum` DESC
LIMIT 1
)
END AS 'product_id',
## name
CASE
WHEN COUNT(`products`.`product_id`)=1 THEN ANY_VALUE(`products`.`name`)
ELSE (
SELECT
`name`
FROM
`products` AS `name_sub`
WHERE 1
AND `name_sub`.`group_id`=`products`.`group_id`
AND `name_sub`.`quantity` > `name_sub`.`minimum`
ORDER BY
`name_sub`.`minimum` DESC
LIMIT 1
)
END AS 'name',
## quantity
CASE
WHEN COUNT(`products`.`product_id`)=1 THEN ANY_VALUE(`products`.`quantity`)
ELSE (
SELECT
`quantity`
FROM
`products` AS `quantity_sub`
WHERE 1
AND `quantity_sub`.`group_id`=`products`.`group_id`
AND `quantity_sub`.`quantity` > `quantity_sub`.`minimum`
ORDER BY
`quantity_sub`.`minimum` DESC
LIMIT 1
)
END AS 'quantity',
## minimum
CASE
WHEN COUNT(`products`.`product_id`)=1 THEN ANY_VALUE(`products`.`minimum`)
ELSE (
SELECT
`minimum`
FROM
`products` AS `minimum_sub`
WHERE 1
AND `minimum_sub`.`group_id`=`products`.`group_id`
AND `minimum_sub`.`quantity` > `minimum_sub`.`minimum`
ORDER BY
`minimum_sub`.`minimum` DESC
LIMIT 1
)
END AS 'minimum',
## group_id
`group_id`
FROM `products`
GROUP BY `group_id`
SELECT
CASE
WHEN COUNT(`products`.`product_id`)=1 THEN JSON_OBJECT(
'product_id', ANY_VALUE(`products`.`product_id`),
'name', ANY_VALUE(`products`.`name`),
'quantity', ANY_VALUE(`products`.`quantity`),
'minimum', ANY_VALUE(`products`.`minimum`),
'name', `products`.`group_id`
)
ELSE (
SELECT
JSON_OBJECT(
'product_id', `product_with_required_quantity`.`product_id`,
'name', `product_with_required_quantity`.`name`,
'quantity', `product_with_required_quantity`.`quantity`,
'minimum', `product_with_required_quantity`.`minimum`,
'name', `product_with_required_quantity`.`group_id`
)
FROM
`products` AS `product_with_required_quantity`
WHERE 1
AND `product_with_required_quantity`.`group_id`=`products`.`group_id`
AND `product_with_required_quantity`.`quantity` > `product_with_required_quantity`.`minimum`
ORDER BY
`product_with_required_quantity`.`minimum` DESC
LIMIT 1
)
END AS 'product'
FROM `products`
GROUP BY `group_id`
foreach ($secondArray as $secondArrayElement) {
$secondArrayElement = (array)$secondArrayElement; // вы везде пишете "массив", но, судя по вашему примеру, у вас тут объект, а не массив. Поэтому я сделал явное преобразование в массив на случай если была ошибка в формулировке.
$doesExistInFirstArray = false;
foreach ($firstArray as $firstArrayElement) {
if ($firstArrayElement['ID'] == $secondArrayElement['id']) {
$doesExistInFirstArray = true;
break;
}
}
$secondArrayElement['doesExistInFirstArray'] = $doesExistInFirstArray;
}
function render($part, array $vars=[]) {
extract($vars);
ob_start();
require __DIR__ . "/views/" . $part . ".php"; // путь тут поправь в соответствии с твоими реалиями
return ob_get_clean();
}
$user_html_entity = render("user_entity", compact(
"user_id",
"user_avatar_link",
"user_nickname",
"user_last_online_datetime",
"user_initials_info_string",
"user_location_string"
));
<a href="/user/<?= $user_id ?>" class="user" data-id="users___user_link">
<div class="section_900">
<img src="<?= $user_avatar_link ?>">
<div class="no_image_content">
<p class="nickname"><?= $user_nickname ?></p>
<p class="online_status"><?= Get_Online_Status_From_Datetime($user_last_online_datetime) ?></p>
<p class="initials"><?= $user_initials_info_string ?></p>
<p class="location"><?= $user_location_string ?></p>
</div>
</div>
</a>
DELETE FROM `cat_product` WHERE `id` IN (SELECT `inner`.`id` FROM(
SELECT `cat_product`.`id` FROM `cat_product` ORDER BY RAND() LIMIT 1
) as `inner`)
SELECT
ANY_VALUE(id) AS 'id',
office_id,
IF(
POSITION(',' IN GROUP_CONCAT(employee_id))=0,
GROUP_CONCAT(employee_id),
SUBSTR(GROUP_CONCAT(employee_id), 1, POSITION(',' IN GROUP_CONCAT(employee_id))-1)
) AS 'employee_id_first',
IF(
POSITION(',' IN GROUP_CONCAT(employee_id))=0,
NULL,
SUBSTR(
RIGHT(GROUP_CONCAT(employee_id), LENGTH(GROUP_CONCAT(employee_id))-POSITION(',' IN GROUP_CONCAT(employee_id))),
1,
POSITION(',' IN RIGHT(GROUP_CONCAT(employee_id), LENGTH(GROUP_CONCAT(employee_id))-POSITION(',' IN GROUP_CONCAT(employee_id))))-1
)
) AS 'employee_id_second'
FROM
t
GROUP BY
office_id
function calculate_discounted_price( $price, $values ) {
$pricequery = (float)$_POST['custom_price'];
$price += $pricequery;
return $price;
}