Concat tên biến php

Hằng số là một mã định danh (tên) cho một giá trị đơn giản. Như tên gợi ý, giá trị đó không thể thay đổi trong quá trình thực thi tập lệnh (ngoại trừ các hằng số ma thuật, không thực sự là hằng số). Các hằng số phân biệt chữ hoa chữ thường. Theo quy ước, định danh hằng luôn là chữ hoa

Ghi chú

Trước PHP 8. 0. 0, các hằng số được xác định bằng hàmdefine() có thể không phân biệt chữ hoa chữ thường

Tên của một hằng tuân theo các quy tắc giống như bất kỳ nhãn nào trong PHP. Tên hằng hợp lệ bắt đầu bằng một chữ cái hoặc dấu gạch dưới, theo sau là bất kỳ số lượng chữ cái, số hoặc dấu gạch dưới nào. Là một biểu thức chính quy, nó sẽ được thể hiện như vậy. ^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$

Có thể định nghĩa các hằng() với các tên dành riêng hoặc thậm chí không hợp lệ, giá trị của chúng chỉ có thể được truy xuất bằng hàm hằng(). Tuy nhiên, làm như vậy là không nên

Ví dụ #1 Tên hằng hợp lệ và không hợp lệ

// Valid constant names
define("FOO", "something");
define("FOO2", "something else");
define("FOO_BAR", "something more");

// Invalid constant names
define("2FOO", "something");

// This is valid, but should be avoided:
// PHP may one day provide a magical constant
// that will break your script
define("__FOO__", "something");

?>

Ghi chú. Đối với mục đích của chúng tôi ở đây, một chữ cái là a-z, A-Z và các ký tự ASCII từ 128 đến 255 (0x80-0xff)

Giống như các siêu toàn cầu, phạm vi của một hằng số là toàn cầu. Các hằng số có thể được truy cập từ bất kỳ đâu trong tập lệnh mà không cần quan tâm đến phạm vi. Để biết thêm thông tin về phạm vi, hãy đọc phần hướng dẫn về phạm vi biến

Ghi chú. Kể từ PHP 7. 1. 0, hằng số lớp có thể khai báo khả năng hiển thị của được bảo vệ hoặc riêng tư, làm cho chúng chỉ khả dụng trong phạm vi phân cấp của lớp mà nó được xác định

I wished to point out that while other comments state that the spread operator should be faster than array_merge, I have actually found the opposite to be true for normal arrays. This is the case in both PHP 7.4 as well as PHP 8.0. The difference should be negligible for most applications, but I wanted to point this out for accuracy.

Below is the code used to test, along with the results:

$before = microtime(true);

________số 8_______

    $array1 = [...$array1,...$array2];
}

$after = microtime(true);
echo ($after-$before) . " sec for spread\n";

$before = microtime(true);

________số 8_______

    $array1 = array_merge($array1,$array2);
}

$after = microtime(true);
echo ($after-$before) . " sec for array_merge\n";
?>

Below is the code used to test, along with the results:0

Below is the code used to test, along with the results:1

Guide to URL paths...

Data: $_SERVER['PHP_SELF']
Data type: String
Purpose: The URL path name of the current PHP file, including path-info (see $_SERVER['PATH_INFO']) and excluding URL query string. Includes leading slash.
Caveat: This is after URL rewrites (i.e. it's as seen by PHP, not necessarily the original call URL).
Works on web mode: Yes
Works on CLI mode: Tenuous (emulated to contain just the exact call path of the CLI script, with whatever exotic relative pathname you may call with, not made absolute and not normalised or pre-resolved)

Data: $_SERVER['SCRIPT_NAME']
Data type: String
Purpose: The URL path name of the current PHP file, excluding path-info and excluding URL query string. Includes leading slash.
Caveat: This is after URL rewrites (i.e. it's as seen by PHP, not necessarily the original call URL).
Caveat: Not set on all PHP environments, may need setting via preg_replace('#\.php/.*#', '.php', $_SERVER['PHP_SELF']).
Works on web mode: Yes
Works on CLI mode: Tenuous (emulated to contain just the exact call path of the CLI script, with whatever exotic relative pathname you may call with, not made absolute and not normalised or pre-resolved)

Data: $_SERVER['REDIRECT_URL']
Data type: String
Purpose: The URL path name of the current PHP file, path-info is N/A and excluding URL query string. Includes leading slash.
Caveat: This is before URL rewrites (i.e. it's as per the original call URL).
Caveat: Not set on all PHP environments, and definitely only ones with URL rewrites.
Works on web mode: Yes
Works on CLI mode: No

Data: $_SERVER['REQUEST_URI']
Data type: String
Purpose: The URL path name of the current PHP file, including path-info and including URL query string. Includes leading slash.
Caveat: This is before URL rewrites (i.e. it's as per the original call URL). *
*: I've seen at least one situation where this is not true (there was another $_SERVER variable to use instead supplied by the URL rewriter), but the author of the URL rewriter later fixed it so probably fair to dismiss this particular note.
Caveat: Not set on all PHP environments, may need setting via $_SERVER['REDIRECT_URL'] . '?' . http_build_query($_GET) [if $_SERVER['REDIRECT_URL'] is set, and imperfect as we don't know what GET parameters were originally passed vs which were injected in the URL rewrite] --otherwise-- $_SERVER['PHP_SELF'] . '?' . http_build_query($_GET).
Works on web mode: Yes
Works on CLI mode: No

Data: $_SERVER['PATH_INFO']
Data type: String
Purpose: Find the path-info, which is data after the .php filename in the URL call. It's a strange concept.
Caveat: Some environments may not support it, it is best avoided unless you have complete server control
Works on web mode: Yes
Works on CLI mode: No

Note that if something is not set it may be missing from $_SERVER, or it may be blank, so use PHP's 'empty' function for your test.