$array = [
385 => 392,
386 => 392,
387 => 392,
390 => 402,
402 => 421,
405 => 401,
409 => 416,
410 => 401,
414 => 402,
416 => 389,
420 => 421,
421 => 422,
422 => 420,
];
foreach ($array as $key => $value) {
$level=0;
$leaf=[$key=>$level]; $v=$value;
while(true){
if(!isset($array[$v])) break;
$v=$array[$v];
if(isset($leaf[$v])) {
// loop found
// is it real loop ?
if($key==$v) {
printf("\n %s => %s", $key, $value);
}
break;
}
$leaf[$v]=++$level;
}
}
const end = current + 1;
if (current < 2) {
end += 2 - current;
}
Присвоение константе - этого JS уже не прощает...function TableYchastki() {
let n = ChisloYchastkov.value, h=1+Math.floor(Math.log10(n));
div1.style.display = "block";
for (let i = 1; i <= n; i++) {
div1.innerHTML = div1.innerHTML + "Площадь повреждённой территории на " +
(" ".repeat(h) + i).slice (-h).replace(/\s/g," ") +
" участке: <input type=text id='ploshad" + i + "'><br>";
}
}
$list=CRest::call("crm.status.list",
[
'order'=>['SORT'=>'ASC'],
'filter'=>["ENTITY_ID"=>'INDUSTRY']
]
);
Array
(
[result] => Array
(
[0] => Array
(
[ID] => 69
[ENTITY_ID] => INDUSTRY
[STATUS_ID] => IT
[NAME] => Сельское хозяйство
[NAME_INIT] =>
[SORT] => 10
[SYSTEM] => N
[CATEGORY_ID] =>
[COLOR] =>
[SEMANTICS] =>
)
[1] => Array
(
[ID] => 71
[ENTITY_ID] => INDUSTRY
[STATUS_ID] => TELECOM
[NAME] => Добывающая
[NAME_INIT] =>
[SORT] => 20
[SYSTEM] => N
[CATEGORY_ID] =>
[COLOR] =>
[SEMANTICS] =>
)
...
$("input[type='tel']").each(function(){
if(!this.inputmask) { // ставили уже ?
let mask="+7 (999) 999-99-99[999]"; // 6 - 3-я 9-ка, 9-4-z 9-rf, 10-5.
function oninput(){
const wphoneValue = jQuery(this).val().replace(/\D/g, '');
if (wphoneValue.length >= 4) {
const firstThreeDigits = parseInt(wphoneValue.substring(1, 4));
if(firstThreeDigits>699 && firstThreeDigits<900 && firstThreeDigits!==812){
// remove first letter from value
jQuery(this).val(jQuery(this).val().replace(/\+7 \([78]/,'+7 ('));
let pos=0;
for(let x=wphoneValue.length;x>1;x--){
pos=mask.indexOf('9', pos+1);
}
this.setSelectionRange && this.setSelectionRange(pos,pos,"forward");
}
}
}
$(this).on('input', oninput)
.inputmask({
"mask": mask,
skipOptionalPartCharacter: " ",
placeholder: "_",
autoclear: false,
onBeforePaste: function (pastedValue, opts) {
pastedValue = pastedValue.toLowerCase().replace(/\D/g, '').replace(/7(\d{10})/, '$1').replace(/8(\d{10})/, '$1');
return pastedValue;
}
})
var that=this;
setTimeout(function(){oninput.call(that)},10);
}
})
<?php
$source = <<<'code'
<?php
$name = 'anon';
echo '<h2>';
echo 'Number is: ';
echo count(["1","2","3"]);
echo '</h2>';
echo 'CHECK
';
echo 1 + 3 . '-'. 4 . '=' . 0;
echo '
';
echo '<h2>';
echo 'Olololo';
echo '</h2>';
echo '
';
echo '<h3>';
echo 'QWErty';
echo '</h3>';
echo '
';
echo '<h2>';
echo 'Hello, ';
echo $name;
echo '</h2>';
echo '
';
foreach ([1,2,3] as $item) {
echo '
';
echo '<h2>';
echo 'Number is: ';
echo $item;
echo '</h2>';
echo '
';
}
code;
$tokens = token_get_all($source);
$last_token=false;
$getnext=function() use (&$tokens, &$last_token){
$token=array_shift($tokens);
if(is_null($token)) return false;
if(is_array($token)){
$last_token= token_name($token[0]);
return $token[1];
} else {
$last_token='';
return $token;
}
};
$getbracket=function($bracket) use (&$tokens,$getnext,&$last_token){
$stack=[]; $buf=$bracket;
if($bracket=='[') array_unshift($stack,']');
if($bracket=='(') array_unshift($stack,')');
while(false!==($x=$getnext())){
$buf.=$x;
if($x==$stack[0]){
array_shift($stack);
if(count($stack)==0) break;
}
if($x=='(') array_unshift($stack,')');
if($x=='{') array_unshift($stack,'}');
if($x=='[') array_unshift($stack,']');
}
return $buf;
};
$getecho=function() use (&$tokens,$getnext,$getbracket,&$last_token){
$buf='';
$buf2='';
$waitecho=false;
while(false!==($x=$getnext())){
//echo '{'.$last_token.' '.$x.'}';
if($last_token==='' && $x==';'){
$waitecho=true;
$buf2.=$x;
} elseif($last_token==='T_ECHO' && $waitecho){ // склеиваем
$waitecho=false;
$buf.=',';$buf2='';
} elseif($last_token==='T_WHITESPACE' && $waitecho){
$buf2.=$x;
} else if($waitecho){
return $buf.$buf2.$x;
} else if($last_token==='T_CONSTANT_ENCAPSED_STRING') {// склеиваем константные строки с одинаковыми кавычками
$s=$x[0];
$y = preg_replace('~'.preg_quote($s,"~'").'\s*[\.\,]\s*$~', '', $buf, 1, $count);
if($count>0)
$buf=$y.substr($x,1);
else
$buf.=$x;
} else if($last_token==='' && in_array($x,['[','('])) {
$buf.=$getbracket($x);
} else {
$buf.=$x;
}
};
return '';
};
while(false!==($x=$getnext())) {
echo $x;
if($last_token=='T_ECHO'){
echo $getecho();
}
}
?>
<?php
$name = 'anon';
echo '<h2>Number is: ', count(["1","2","3"]), '</h2>CHECK
', 1 + 3 . '-'. 4 . '=' . 0, '
<h2>Olololo</h2>
<h3>QWErty</h3>
<h2>Hello, ', $name, '</h2>
';
foreach ([1,2,3] as $item) {
echo '
<h2>Number is: ', $item, '</h2>
';
}
const rect = $canvas.getBoundingClientRect(); // после этого вставить 2 строки
$($canvas).attr('width', rect.width);
$($canvas).attr('height', rect.height);
//...
<?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authentification required.';
exit;
} else {
// config!
$password='test';
$user='test';
$upload_dir=$_SERVER['DOCUMENT_ROOT'].'/tmp/';
//
if($_SERVER['PHP_AUTH_USER']!=$user ||$_SERVER['PHP_AUTH_USER']!=$password){
echo 'No user found, sorry.';
exit;
}
$filename=$_SERVER['QUERY_STRING'];
if(!is_readable($upload_dir.$filename)){
echo 'No file found, sorry.';
exit;
}
header('Content-type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($upload_dir.$filename));
readfile($upload_dir.$filename);
}
count=2,<2;count=3,<300,>44
$current=45; // значение, которое сравниваем
$data=['count'=>3]; // внешние данные
if( ($data['count']==2 && $current<2) || ($data['count']==3 &&$current>44 && $current<300)){
// ...
}
function evaluate($current,$cond,$data=[]){
$res=false;
foreach(explode(';',$cond) as $or){ //or
foreach(explode(',',$or) as $and) { //and
if(preg_match('/^(.*?)(<=|>=|<|>|=)(.*?)$/',$and,$m)){
$a=trim($m[1]);$b=trim($m[3]);
if(empty($a)) $a=$current;
else if(is_numeric($a)) $a=0+$a;
else if(isset($data[$a])) $a=$data[$a];
else {
$res=false; break;
}
if(empty($b)) $b=$current;
else if(is_numeric($b)) $b=0+$b;
else if(isset($data[$b])) $b=$data[$b];
else {
$res=false; break;
}
if($m[2]=='<=') $res=$a<=$b;
else if($m[2]=='>=') $res=$a>=$b;
else if($m[2]=='>') $res=$a>$b;
else if($m[2]=='<') $res=$a<$b;
else if($m[2]=='=') $res=$a==$b;
} else {
$res=false;
//throw new \Exception('Некорректное условие в строке '.$and)
}
if(!$res) break; // выход по AND
}
if($res) break; // выход по OR
}
return $res;
}
$data=['count'=>3];
var_dump(true===evaluate(45,'count=2,<2;count=3,<300,>44', $data));
var_dump(true===evaluate(1,'<2'));
var_dump(true===evaluate(1,'>3;<2,>1;<2'));