<?php
namespace App;
class Task extends Model
{
public static function getTasks()
{
$tasks = App\Task::get();
return $tasks;
}
}
$json[0]
не отрабатывает, потому что у вас нет 0 индекса<?php
$url = file_get_contents('https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC,ETH,BCH&tsyms=BTC,USD&api_key=MY-API-KEY');
$json = json_decode($url, true);
echo 'Eth to usd: ' . $json['ETH']['USD'];
<?php
$START_DATE = "01.04.2019";
$END_DATE = "31.04.2019";
$object_list = [
[
"num" => "0003000000006739",
"qr_code" => "18826807734421200000",
"entry_date" => "23.03.2019 16:43",
],
[
"num" => "0003000000006739",
"qr_code" => "18826807734421200000",
"entry_date" => "23.04.2019 16:43",
],
[
"num" => "0003000000006739",
"qr_code" => "18826807734421200000",
"entry_date" => "23.05.2019 16:43"
]
];
$ts_from = strtotime($START_DATE);
$ts_to = strtotime($END_DATE);
foreach ($object_list as $item) {
$ts = strtotime($item['entry_date']);
if ($ts > $ts_from && $ts <= $ts_to) {
echo '<pre style="color: red;">', print_r($item, true), '</pre>';
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://yourdomain.com/wp-json/wp/v2/posts?status=draft');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_USERPWD, 'username' . ':' . 'password');
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
<?php
$data = [
'access_token' => 'ключ_доступа_сообщества',
'v' => 5.95
];
$url = 'https://api.vk.com/method/messages.getConversations?' . http_build_query($data);
$data = file_get_contents($url);
$json = json_decode($data, true);
$users = [];
foreach ($json['response']['items'] as $item) {
$userId = $item['conversation']['peer']['id'];
$users[] = $userId;
}
print_r($users, true);
/opt/php/7.0/bin/php
Validate::getMessage()
статичный?class Validate
{
private $name;
private $phone;
public $result = [];
public function __construct(string $name, string $phone)
{
$this->phone = $phone;
$this->name = $name;
}
public function getValidate()
{
if (!$this->name && !$this->phone){
return $this->getMessage(true, 'Заполните имя и телефон');
} elseif (!$this->name){
return $this->getMessage(true, 'Заполните имя');
} elseif (!$this->phone){
return $this->getMessage(true, 'Заполните телефон');
} else {
return $this->getMessage(false, 'Сообщение отправлено');
}
}
public function getMessage(bool $error, string $message)
{
return $this->result = [
'error' => $error,
'message' => $message
];
}
}
<?php
$val = 150000;
$point = 50000;
$result = ceil($val / $point); // с округлением в большую сторону
$result = floor($val / $point); // с округлением в меньшую сторону
$result = round($val / $point); // по правилам математического округления