https://мойсервер/telegrambot/file.php?apibot=24953021_______Pnjwywdkg&chatid=-1003333102111&document=%D0%9F%D1%80%D0%BE%D0%B4%D0%B0%D0%B6%D0%B8_%D0%BC%D0%B5%D1%81%D1%8F%D1%86_%D0%BC%D0%B0%D0%B9.xls
$width, $image
и т.д. Эти переменные надо передавать как аргументы функцииfunction someFunction($width)
{
return ++$width;
}
function someFunction()
{
global $width;
// do something with $width
}
class BlogPost extends Post implements JsonSerializable {
//...
public function jsonSerialize() {
return [
'title' => $this->title,
'attachments' => $this->attachments,
...
];
}
}
return json_encode($blogPost);
$m = new \MongoClient();
class IpAddressExclusion
{
static private $instance;
private $cache;
private $excluded = [
'192.168.1.1',
'192.168.1.2',
'192.168.1.3',
];
private function __construct()
{
}
private function setCache($key, $value)
{
if (!isset($this->cache[$key])) {
$this->cache[$key] = $value;
}
}
private function getCache($key)
{
if ($this->hasCache($key)) {
return $this->cache[$key];
}
return null;
}
private function hasCache($key)
{
return isset($this->cache[$key]);
}
public function isExcluded($ip)
{
$search = array_search($ip, $this->excluded);
if ($search && $search !== 0) {
if ($this->hasCache($ip)) {
return $this->getCache($ip);
} else {
$this->setCache($ip, true);
}
return true;
}
return false;
}
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new IpAddressExclusion();
}
return self::$instance;
}
}
if (IpAddressExclusion::getInstance()->isExcluded('192.168.1.1')) {
//Делам что то
}
<?php
$array = [
'one' => [
'one_subOne','one_subTwo','one_subThree'
],
'two' => [
'two_subOne','two_subTwo','two_subThree'
],
'three' => [
'three_subOne','three_subTwo','three_subThree'
],
'four' => [
'four_subOne','four_subTwo','four_subThree'
],
];
//Вариант 1 - но тогда внутренний указатель массива будет установлен на
//последний элемент
print_r(end($array));
//Вариант 2
print_r(array_slice($array,-1));
//Вариант 3 - но тогда последний элемент будет удален из массива $array
print_r(array_pop($array));
class News
{
private $posts = [];
private $db;
/**
* news constructor.
*
* @param $db
*/
public function __construct($db)
{
$this->db = $db;
}
public function getPosts()
{
$res = $this->db->query("SELECT `id`, `name` FROM `posts`");
while ($row = $res->fetch_assoc()) {
$this->posts[$row['id']] = $row['name'];
}
return $this->posts;
}
}
function db_Iconnect()
{
$db = new mysqli(HOST_NAME, USER_NAME, MYSQL_PASS, DATABASE_NAME);
return $db;
}
$db = db_Iconnect();
$news = new News($db);
$posts = $news->getPosts();