$b = $a = range('a', 'z');
$result = [];
foreach ($a as $_1) {
foreach ($b as $_2) {
$result[] = "$_1-$_2";
}
}
print_r($result);
<?php
$calc = function(){
$act = ''; $a = $b = 0;
extract($_POST);
$a = (int) $a;
$b = (int) $b;
return preg_match('~^[*/+-]$~', $act) ? eval("return $a $act $b;") : false;
};
$_SERVER['REQUEST_METHOD'] != 'POST' ?: print $calc();
?>
<form method="post">
<input type="text" name="a" />
<input type="text" name="b" />
<?php foreach (['+', '-', '*', '/'] as $act): ?>
<input type="submit" name="act" value="<?=$act?>" />
<?php endforeach; ?>
</form>
$text = 'Not enough data
jkl
Not enough data';
$total = preg_match_all('/Not enough data/', $text, $matches);
var_dump($total, $matches);
$text = 'Привет, [name] !';
$text = preg_replace('~\[name\]~', 'Имя', $text);
echo $text;
$text = 'Привет, [name] !';
$text = str_replace('[name]', 'Имя', $text);
echo $text;
$test_mass[] = [
"lesson_name" => "Установка",
"текст1",
"текст2",
"текст3"
];
$test_mass[] = [
"lesson_name" => "Виды настроек",
"текст4",
"текст5",
"текст6",
"текст7",
];
$out_text = '';
foreach ($test_mass as $mas) {
foreach ($mas as $key => $text) {
if ($key === 'lesson_name') {
$out_text .= '-';
}
$out_text .= $text . "</br>";
}
}
echo $out_text;
$string = " ~~~ любой текст ~~~ [token|234] ~~~ любой текст ~~~ ";
$string = preg_replace('~\[token\|\d+\]\h*~', '', $string);
echo $string;
$array = [
'premium contact',
'premium contact 2',
'premium3 contact 3',
'sport contact 2',
'sport vanco 2'
];
$result = [];
foreach ($array as $item) {
$key = substr($item, 0, 5);
$result[$key][] = $item;
}
$result = array_values($result);
print_r($result);
/*
Array
(
[0] => Array
(
[0] => premium contact
[1] => premium contact 2
[2] => premium3 contact 3
)
[1] => Array
(
[0] => sport contact 2
[1] => sport vanco 2
)
)
*/
к примеру сложить первые три индекса
$arr = [0 => 12, 1 => 15, 2 => 15, 3 => 75, 4 => 77, 5 => 40, 6 => 15, 7 => 2, 8 => 40, 9 => 11, 10 => 8];
$slice = array_slice($arr, 0, 3);
$result = array_sum($slice) / sizeof($slice);
echo $result;
$text = '<span class="wpcf7-form-control wpcf7-acceptance">
<span class="wpcf7-list-item">
<input type="checkbox" name="our-policy" value="1" aria-invalid="false" class="form-check-input" id="our-policy">
</span>
<span class="list-item">
<input type="checkbox" name="our-policy" value="1" aria-invalid="false" class="form-check-input" id="our-policy">
</span>
<span class="wpcf7-list-item">
<input type="checkbox" name="our-policy" value="1" aria-invalid="false" class="form-check-input" id="our-policy">
</span>
</span>';
$patterns = [
'~<span[^>]*wpcf7[^>]*>\s*(<input[^>]+>)\s*</span>~s',
'~<span[^>]*wpcf7[^>]*>(.+)</span>~s'
];
$text = preg_replace($patterns, '$1', $text);
echo $text;
/* Результат:
<input type="checkbox" name="our-policy" value="1" aria-invalid="false" class="form-check-input" id="our-policy">
<span class="list-item">
<input type="checkbox" name="our-policy" value="1" aria-invalid="false" class="form-check-input" id="our-policy">
</span>
<input type="checkbox" name="our-policy" value="1" aria-invalid="false" class="form-check-input" id="our-policy">
*/
Function GetDate(ByVal str As String)
Dim day As String, month As String, year As String
year = Left(str, 2)
month = Mid(str, 3, 2)
day = Mid(str, 5, 2)
If year > 30 Then year = year + 1900 Else year = year + 2000
GetDate = year & "." & month & "." & day
End Function
Sub ПолучитьДату()
Dim result As String
On Error Resume Next
result = InputBox("Введите число", "Диалоговое окно", "921205400655")
ActiveCell = GetDate(result)
End Sub