$even_img_diff = 100; // задайте тут число по вкусу. Это максимальная разница между шириной и высотой при которой картинка будет счиататься "квадратной".
$img_diff = abs($imgwidth_max-$imgheight);
if ($img_diff <= $even_img_diff ) {
// почти квадратная
} elseif ($imgwidth_max > $imgheight) {
$imgclass = '2';
} elseif ($imgwidth_max < $imgheight) {
$imgclass = '3';
}
function setValue($value, $key, array &$arr) {
foreach ($arr as $arrKey=>&$arrValue) {
if ($arrKey == $key) {
$arrValue = $value;
} elseif (is_array($arrValue)) {
setValue($value, $key, $arrValue);
} else {
throw new \InvalidArgumentException("Key {$key} not found in array");
}
}
return $arr;
}
// Check
$Arr['key1']['key2']['key3']['key4']['key5']['keyn'] = null;
setValue('Test Value', "keyn", $Arr);
var_dump($Arr);
/*
array(1) {
["key1"]=>
array(1) {
["key2"]=>
array(1) {
["key3"]=>
array(1) {
["key4"]=>
array(1) {
["key5"]=>
array(1) {
["keyn"]=>
string(10) "Test Value"
}
}
}
}
}
}
*/
<script src="https://smtpjs.com/v3/smtp.js">
</script>
Email.send({
Host : "smtp.yourisp.com",
Username : "username",
Password : "password",
To : 'them@website.com',
From : "you@isp.com",
Subject : "This is the subject",
Body : "And this is the body"
}).then(
message => alert(message)
);
$stmt = $conn->prepare("INSERT INTO MyGuests2 (text2) VALUES (?)");
$stmt->bind_param("s", $name);
$stmt->execute();
$stmt->close();
<group-task :task="'{{ json_encode( $task ) }}'"></group-task>
<group-task :task="'{{ urlencode(json_encode( $task )) }}'"></group-task>
JSON.parse(decodeURIComponent(serialized))
$data = [
["яблоко", "1-01-2019", "1"],
["апельсин", "2-01-2019", "2"],
["мандарин", "2-01-2019", "3"]
];
function buildTable($data) {
$html = "<table>";
/* Build header */
$html .= "<tr>
<td>Название</td>";
foreach ($data as $element) {
list($fruit, $date, $number) = $element;
$html .= "<td>{$date}</td>";
}
$html .= "</tr>";
/* Build body */
foreach ($data as $element) {
list($fruit, $date, $number) = $element;
$html .= "<tr>";
$html .= "<td>{$fruit}</td>";
foreach ($data as $index=>$el) {
$html .= "<td>";
$html .= ($index+1) == $number ? $number : null;
$html .= "</td>";
}
$html .= "</tr>";
}
$html .= "</table>";
return $html;
}
class X {
function index() {
var_dump(__CLASS__); // X
$a = function() {
var_dump(__CLASS__); // X
};
$a();
}
}
$calls = [
['prefix' => '+57'],
['prefix' => '+268'],
['prefix' => '+972'],
['prefix' => '+972'],
['prefix' => '+33'],
['prefix' => '+33'],
['prefix' => '+972'],
['prefix' => '+509'],
['prefix' => ''],
['prefix' => '+33'],
['prefix' => '+268'],
['prefix' => '+57'],
];
function calcPrefixStat($calls) {
$stat = [];
foreach($calls as $call) {
if (!array_key_exists($call['prefix'], $stat)) {
$stat[$call['prefix']] = 0;
}
$stat[$call['prefix']]++;
}
return $stat;
}
var_dump(calcPrefixStat($calls));
/*
array(6) {
["+57"]=>
int(2)
["+268"]=>
int(2)
["+972"]=>
int(3)
["+33"]=>
int(3)
["+509"]=>
int(1)
[""]=>
int(1)
}
*/