- Используйте require, когда файл требуется приложению.
- Используйте include, когда файл не требуется, и приложение должно продолжаться, когда файл не найден.
set_time_limit(0);
ini_set('max_execution_time', 0); // не сработает, если включен безопасный режим
$users = [
'u101',
'u402',
'u503',
'u703',
'u114',
'u148',
'u152',
'u173',
'u134'
];
$string = implode(" OR ", $users); // u101 OR u402 OR u503 OR u703 OR u114 OR u148 OR u152 OR u173 OR u134;
"... WHERE `akk` IN (" . implode(",", $users) . ");";
$var = explode(',', $fabricsVal);
$arrFilter = array("SECTION_ID"=>$var);
if (file_exists($filename) && is_file($filename)) {
$content = file_get_contents($filename)
}
is_file возвращает TRUE, если файл существует и является обычным файлом, иначе возвращает FALSE.
if (is_file($filename)) {
$content = file_get_contents($filename);
}
if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
echo 'Я использую PHP версии не ниже 7.0.0, моя версия: ' . PHP_VERSION . "\n";
}
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
echo 'Я использую PHP версии не ниже 5.3.0, моя версия: ' . PHP_VERSION . "\n";
}
if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
echo 'Я использую PHP 5.0.0 или выше, моя версия: ' . PHP_VERSION . "\n";
}
if (version_compare(PHP_VERSION, '5.0.0', '<')) {
echo 'Я до сих пор использую PHP 4, моя версия: ' . PHP_VERSION . "\n";
}
$date = DateTime::createFromFormat('d.m.Y \| H:i', '07.09.2018 | 00:55');
echo $date->format('d.m.Y'); // 07.09.2018
echo $date->format('H:i'); // 00:55
class A
{
public function print()
{
return 'Some text...';
}
}
Class B
{
protected $a;
public function __construct(A $a)
{
$this->a = $a;
}
public function print(){
return $this->a->print();
}
}
$a = new A();
$b = new B($a);
echo $b->print(); // Some text...
$date = DateTime::createFromFormat('m-d-Y, H:i A', '05-21-2005, 12:27 AM');
echo $date->format('Y-m-d H:i:s'); // 2005-05-21 00:27:00
// array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
foreach (range(0, 12) as $number) {
echo $number;
}
implode(',', range(41, 44)); // 41,42,43,44
$document = new Document($html);
// OR
$document = new Document();
$document->loadHtml($html);
И мини-вопрос: как использовать first()?
$html = '<div>Foo<span>Bar</span><!--Baz--></div>';
$document = new Document($html);
$div = $document->first('div');
Значения DateTime отображаются в виде строк JSON в виде "/Date (700000 +0500)/", где первое число (700000 в приведенном примере) - это количество миллисекунд в часовом поясе GMT, регулярное (не дневная летняя экономия ) время с полуночи, 1 января 1970 года. Число может быть отрицательным для представления более ранних времен. Часть, которая состоит из "+0500" в примере, является необязательной и указывает, что время относится к локальному виду, то есть должно быть преобразовано в локальный часовой пояс при десериализации. Если он отсутствует, время десериализуется как Utc.
DateTime Wire Format
DateTime values appear as JSON strings in the form of "/Date(700000+0500)/", where the first number (700000 in the example provided) is the number of milliseconds in the GMT time zone, regular (non-daylight savings) time since midnight, January 1, 1970. The number may be negative to represent earlier times. The part that consists of "+0500" in the example is optional and indicates that the time is of the Local kind - that is, should be converted to the local time zone on deserialization. If it is absent, the time is deserialized as Utc. The actual number ("0500" in this example) and its sign (+ or -) are ignored.
When serializing DateTime, Local and Unspecified times are written with an offset, and Utc is written without.
The ASP.NET AJAX client JavaScript code automatically converts such strings into JavaScript DateTime instances. If there are other strings that have a similar form that are not of type DateTime in .NET, they are converted as well.
The conversion only takes place if the "/" characters are escaped (that is, the JSON looks like "\/Date(700000+0500)\/"), and for this reason WCF's JSON encoder (enabled by the WebHttpBinding) always escapes the "/" character.
echo time() * 1000 . date('O'); // 1533822186000+0300
O - Разница с временем по Гринвичу, в часах
$obj = (object) array('1' => 'foo');
//output foo
echo $obj->{'1'};
Операторы, работающие с массивами:
$a == $b Равно
$a === $b Тождественно равно
$a = array('1', '2', '3');
$b = array('1', '2', '3');
var_dump($a === $b); // bool(true)
var_dump(count(array_diff($a, $b)) === 0);// bool(true)
$a = array('1', '2', '3', '4', '5');
$b = array('1', '2', '3');
var_dump($a === $b); // bool(false)
var_dump(count(array_diff($a, $b)) === 0);// bool(false)
function seconds2times($seconds, $count_zero = TRUE, $output = 'years,days,hours,minutes,seconds')
{
// Normalize output
$output = trim(strtolower((string)$output));
if (!$output) {
// Invalid output
return FALSE;
}
// Array with the output formats
$output = preg_split('/[^a-z]+/', $output);
// Convert the list of outputs to an associative array
$output = array_combine($output, array_fill(0, count($output), 0));
// Make the output values into keys
extract(array_flip($output), EXTR_SKIP);
$times = [];
// Seconds per minute | hour | day | year
$periods = [60, 3600, 86400, 31556926,];
for ($i = 3; $i >= 0; $i--) {
$period = floor($seconds / $periods[$i]);
if (($period > 0) || ($period == 0 && $count_zero)) {
$times[$i + 1] = $period;
$seconds -= $period * $periods[$i];
$count_zero = TRUE;
}
}
$times[0] = $seconds;
$result = [];
if (isset($output['years'])) {
$result['years'] = $times[4];
}
if (isset($output['days'])) {
$result['days'] = $times[3];
}
if (isset($output['hours'])) {
$result['hours'] = $times[2];
}
if (isset($output['minutes'])) {
$result['minutes'] = $times[1];
}
if (isset($output['seconds'])) {
$result['seconds'] = $times[0];
}
return $result;
}
$time = '2d 9h 40m';
if (preg_match('/([\d]*)d\s([\d]*)h\s([\d]*)m/', $time, $matches)) {
list($time, $days, $hours, $minutes) = $matches;
$seconds = ($days * 86400) + ($hours * 3600) + ($minutes * 60);
$seconds = $seconds - ($seconds / 100 * 20); // -20%
print_r(seconds2times($seconds));
// Array ( [years] => 0 [days] => 1 [hours] => 22 [minutes] => 8 [seconds] => 0 )
}