I did a performance check, and I saw, if you push more than one value it can be faster the array push, that the normal $array[] version.
Case 1: $array[] = something; Case 2: array_push($array, $value); Case 3: array_push($array, $value1, $value2, $value3 [...]); $values are definied Case 4: array_push($array, $value1, $value2, $value3 [...]); $values are definied, when $array is not empty Case 5: Case1 + Case 3 Case 6: Result array contains some value (Case 4) Case 7: Result array contains same value as the push array (Case 4) ----------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~ Case 1 ~~~~~~~~~~~~ Times: 0.0310 0.0300 0.0290 0.0340 0.0400 0.0440 0.0480 0.0550 0.0570 0.0570 Min: 0.0290 Max: 0.0570 Avg: 0.0425 ~~~~~~~~~~~~ Case 2 ~~~~~~~~~~~~ Times: 0.3890 0.3850 0.3770 0.4110 0.4020 0.3980 0.4020 0.4060 0.4130 0.4200 Min: 0.3770 Max: 0.4200 Avg: 0.4003 ~~~~~~~~~~~~ Case 3 ~~~~~~~~~~~~ Times: 0.0200 0.0220 0.0240 0.0340 0.0360 0.0410 0.0460 0.0500 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0377 ~~~~~~~~~~~~ Case 4 ~~~~~~~~~~~~ Times: 0.0200 0.0250 0.0230 0.0260 0.0330 0.0390 0.0460 0.0510 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0367 ~~~~~~~~~~~~ Case 5 ~~~~~~~~~~~~ Times: 0.0260 0.0250 0.0370 0.0360 0.0390 0.0440 0.0510 0.0520 0.0530 0.0560 Min: 0.0250 Max: 0.0560 Avg: 0.0419 ~~~~~~~~~~~~ Case 6 ~~~~~~~~~~~~ Times: 0.0340 0.0280 0.0370 0.0410 0.0450 0.0480 0.0560 0.0580 0.0580 0.0570 Min: 0.0280 Max: 0.0580 Avg: 0.0462 ~~~~~~~~~~~~ Case 7 ~~~~~~~~~~~~ Times: 0.0290 0.0270 0.0350 0.0410 0.0430 0.0470 0.0540 0.0540 0.0550 0.0550 Min: 0.0270 Max: 0.0550 Avg: 0.044
Tester code: // Case 1 $startTime = microtime(true); $array = array(); for ($x = 1; $x <= 100000; $x++) { $array[] = $x; } $endTime = microtime(true);
// Case 2 $startTime = microtime(true); $array = array(); for ($x = 1; $x <= 100000; $x++) { array_push($array, $x); } $endTime = microtime(true);
// Case 3 $result = array(); $array2 = array(&$result)+$array; $startTime = microtime(true); call_user_func_array("array_push", $array2); $endTime = microtime(true);
// Case 4 $result = array(); for ($x = 1; $x <= 100000; $x++) { $result[] = $x; } $array2 = array(&$result)+$array; $startTime = microtime(true); call_user_func_array("array_push", $array2); $endTime = microtime(true);
// Case 5 $result = array(); $startTime = microtime(true); $array = array(&$result); for ($x = 1; $x <= 100000; $x++) { $array[] = $x; } $endTime = microtime(true);
// Case 6 $result = array(1,2,3,4,5,6); $startTime = microtime(true); $array = array(&$result); for ($x = 1; $x <= 100000; $x++) { $array[] = $x; } $endTime = microtime(true);
________số 8 Trong hướng dẫn này, chúng tôi sử dụng echo hoặc Case 1: $array[] = something; Case 2: array_push($array, $value); Case 3: array_push($array, $value1, $value2, $value3 [...]); $values are definied Case 4: array_push($array, $value1, $value2, $value3 [...]); $values are definied, when $array is not empty Case 5: Case1 + Case 3 Case 6: Result array contains some value (Case 4) Case 7: Result array contains same value as the push array (Case 4) ----------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~ Case 1 ~~~~~~~~~~~~ Times: 0.0310 0.0300 0.0290 0.0340 0.0400 0.0440 0.0480 0.0550 0.0570 0.0570 Min: 0.0290 Max: 0.0570 Avg: 0.0425 ~~~~~~~~~~~~ Case 2 ~~~~~~~~~~~~ Times: 0.3890 0.3850 0.3770 0.4110 0.4020 0.3980 0.4020 0.4060 0.4130 0.4200 Min: 0.3770 Max: 0.4200 Avg: 0.4003 ~~~~~~~~~~~~ Case 3 ~~~~~~~~~~~~ Times: 0.0200 0.0220 0.0240 0.0340 0.0360 0.0410 0.0460 0.0500 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0377 ~~~~~~~~~~~~ Case 4 ~~~~~~~~~~~~ Times: 0.0200 0.0250 0.0230 0.0260 0.0330 0.0390 0.0460 0.0510 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0367 ~~~~~~~~~~~~ Case 5 ~~~~~~~~~~~~ Times: 0.0260 0.0250 0.0370 0.0360 0.0390 0.0440 0.0510 0.0520 0.0530 0.0560 Min: 0.0250 Max: 0.0560 Avg: 0.0419 ~~~~~~~~~~~~ Case 6 ~~~~~~~~~~~~ Times: 0.0340 0.0280 0.0370 0.0410 0.0450 0.0480 0.0560 0.0580 0.0580 0.0570 Min: 0.0280 Max: 0.0580 Avg: 0.0462 ~~~~~~~~~~~~ Case 7 ~~~~~~~~~~~~ Times: 0.0290 0.0270 0.0350 0.0410 0.0430 0.0470 0.0540 0.0540 0.0550 0.0550 Min: 0.0270 Max: 0.0550 Avg: 0.044 0 trong hầu hết mọi ví dụ. Vì vậy, chương này chứa thêm một chút thông tin về hai câu lệnh đầu ra đó
Câu lệnh echo và print PHPecho và Case 1: $array[] = something; Case 2: array_push($array, $value); Case 3: array_push($array, $value1, $value2, $value3 [...]); $values are definied Case 4: array_push($array, $value1, $value2, $value3 [...]); $values are definied, when $array is not empty Case 5: Case1 + Case 3 Case 6: Result array contains some value (Case 4) Case 7: Result array contains same value as the push array (Case 4) ----------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~ Case 1 ~~~~~~~~~~~~ Times: 0.0310 0.0300 0.0290 0.0340 0.0400 0.0440 0.0480 0.0550 0.0570 0.0570 Min: 0.0290 Max: 0.0570 Avg: 0.0425 ~~~~~~~~~~~~ Case 2 ~~~~~~~~~~~~ Times: 0.3890 0.3850 0.3770 0.4110 0.4020 0.3980 0.4020 0.4060 0.4130 0.4200 Min: 0.3770 Max: 0.4200 Avg: 0.4003 ~~~~~~~~~~~~ Case 3 ~~~~~~~~~~~~ Times: 0.0200 0.0220 0.0240 0.0340 0.0360 0.0410 0.0460 0.0500 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0377 ~~~~~~~~~~~~ Case 4 ~~~~~~~~~~~~ Times: 0.0200 0.0250 0.0230 0.0260 0.0330 0.0390 0.0460 0.0510 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0367 ~~~~~~~~~~~~ Case 5 ~~~~~~~~~~~~ Times: 0.0260 0.0250 0.0370 0.0360 0.0390 0.0440 0.0510 0.0520 0.0530 0.0560 Min: 0.0250 Max: 0.0560 Avg: 0.0419 ~~~~~~~~~~~~ Case 6 ~~~~~~~~~~~~ Times: 0.0340 0.0280 0.0370 0.0410 0.0450 0.0480 0.0560 0.0580 0.0580 0.0570 Min: 0.0280 Max: 0.0580 Avg: 0.0462 ~~~~~~~~~~~~ Case 7 ~~~~~~~~~~~~ Times: 0.0290 0.0270 0.0350 0.0410 0.0430 0.0470 0.0540 0.0540 0.0550 0.0550 Min: 0.0270 Max: 0.0550 Avg: 0.044 0 ít nhiều giống nhau. Cả hai đều được sử dụng để xuất dữ liệu ra màn hình
Sự khác biệt là nhỏ. echo không có giá trị trả về trong khi Case 1: $array[] = something; Case 2: array_push($array, $value); Case 3: array_push($array, $value1, $value2, $value3 [...]); $values are definied Case 4: array_push($array, $value1, $value2, $value3 [...]); $values are definied, when $array is not empty Case 5: Case1 + Case 3 Case 6: Result array contains some value (Case 4) Case 7: Result array contains same value as the push array (Case 4) ----------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~ Case 1 ~~~~~~~~~~~~ Times: 0.0310 0.0300 0.0290 0.0340 0.0400 0.0440 0.0480 0.0550 0.0570 0.0570 Min: 0.0290 Max: 0.0570 Avg: 0.0425 ~~~~~~~~~~~~ Case 2 ~~~~~~~~~~~~ Times: 0.3890 0.3850 0.3770 0.4110 0.4020 0.3980 0.4020 0.4060 0.4130 0.4200 Min: 0.3770 Max: 0.4200 Avg: 0.4003 ~~~~~~~~~~~~ Case 3 ~~~~~~~~~~~~ Times: 0.0200 0.0220 0.0240 0.0340 0.0360 0.0410 0.0460 0.0500 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0377 ~~~~~~~~~~~~ Case 4 ~~~~~~~~~~~~ Times: 0.0200 0.0250 0.0230 0.0260 0.0330 0.0390 0.0460 0.0510 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0367 ~~~~~~~~~~~~ Case 5 ~~~~~~~~~~~~ Times: 0.0260 0.0250 0.0370 0.0360 0.0390 0.0440 0.0510 0.0520 0.0530 0.0560 Min: 0.0250 Max: 0.0560 Avg: 0.0419 ~~~~~~~~~~~~ Case 6 ~~~~~~~~~~~~ Times: 0.0340 0.0280 0.0370 0.0410 0.0450 0.0480 0.0560 0.0580 0.0580 0.0570 Min: 0.0280 Max: 0.0580 Avg: 0.0462 ~~~~~~~~~~~~ Case 7 ~~~~~~~~~~~~ Times: 0.0290 0.0270 0.0350 0.0410 0.0430 0.0470 0.0540 0.0540 0.0550 0.0550 Min: 0.0270 Max: 0.0550 Avg: 0.044 0 có giá trị trả về là 1 nên có thể dùng trong biểu thức. echo có thể nhận nhiều tham số (mặc dù việc sử dụng như vậy rất hiếm) trong khi Case 1: $array[] = something; Case 2: array_push($array, $value); Case 3: array_push($array, $value1, $value2, $value3 [...]); $values are definied Case 4: array_push($array, $value1, $value2, $value3 [...]); $values are definied, when $array is not empty Case 5: Case1 + Case 3 Case 6: Result array contains some value (Case 4) Case 7: Result array contains same value as the push array (Case 4) ----------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~ Case 1 ~~~~~~~~~~~~ Times: 0.0310 0.0300 0.0290 0.0340 0.0400 0.0440 0.0480 0.0550 0.0570 0.0570 Min: 0.0290 Max: 0.0570 Avg: 0.0425 ~~~~~~~~~~~~ Case 2 ~~~~~~~~~~~~ Times: 0.3890 0.3850 0.3770 0.4110 0.4020 0.3980 0.4020 0.4060 0.4130 0.4200 Min: 0.3770 Max: 0.4200 Avg: 0.4003 ~~~~~~~~~~~~ Case 3 ~~~~~~~~~~~~ Times: 0.0200 0.0220 0.0240 0.0340 0.0360 0.0410 0.0460 0.0500 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0377 ~~~~~~~~~~~~ Case 4 ~~~~~~~~~~~~ Times: 0.0200 0.0250 0.0230 0.0260 0.0330 0.0390 0.0460 0.0510 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0367 ~~~~~~~~~~~~ Case 5 ~~~~~~~~~~~~ Times: 0.0260 0.0250 0.0370 0.0360 0.0390 0.0440 0.0510 0.0520 0.0530 0.0560 Min: 0.0250 Max: 0.0560 Avg: 0.0419 ~~~~~~~~~~~~ Case 6 ~~~~~~~~~~~~ Times: 0.0340 0.0280 0.0370 0.0410 0.0450 0.0480 0.0560 0.0580 0.0580 0.0570 Min: 0.0280 Max: 0.0580 Avg: 0.0462 ~~~~~~~~~~~~ Case 7 ~~~~~~~~~~~~ Times: 0.0290 0.0270 0.0350 0.0410 0.0430 0.0470 0.0540 0.0540 0.0550 0.0550 Min: 0.0270 Max: 0.0550 Avg: 0.044 0 có thể nhận một tham số. echo nhanh hơn một chút so với Case 1: $array[] = something; Case 2: array_push($array, $value); Case 3: array_push($array, $value1, $value2, $value3 [...]); $values are definied Case 4: array_push($array, $value1, $value2, $value3 [...]); $values are definied, when $array is not empty Case 5: Case1 + Case 3 Case 6: Result array contains some value (Case 4) Case 7: Result array contains same value as the push array (Case 4) ----------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~ Case 1 ~~~~~~~~~~~~ Times: 0.0310 0.0300 0.0290 0.0340 0.0400 0.0440 0.0480 0.0550 0.0570 0.0570 Min: 0.0290 Max: 0.0570 Avg: 0.0425 ~~~~~~~~~~~~ Case 2 ~~~~~~~~~~~~ Times: 0.3890 0.3850 0.3770 0.4110 0.4020 0.3980 0.4020 0.4060 0.4130 0.4200 Min: 0.3770 Max: 0.4200 Avg: 0.4003 ~~~~~~~~~~~~ Case 3 ~~~~~~~~~~~~ Times: 0.0200 0.0220 0.0240 0.0340 0.0360 0.0410 0.0460 0.0500 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0377 ~~~~~~~~~~~~ Case 4 ~~~~~~~~~~~~ Times: 0.0200 0.0250 0.0230 0.0260 0.0330 0.0390 0.0460 0.0510 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0367 ~~~~~~~~~~~~ Case 5 ~~~~~~~~~~~~ Times: 0.0260 0.0250 0.0370 0.0360 0.0390 0.0440 0.0510 0.0520 0.0530 0.0560 Min: 0.0250 Max: 0.0560 Avg: 0.0419 ~~~~~~~~~~~~ Case 6 ~~~~~~~~~~~~ Times: 0.0340 0.0280 0.0370 0.0410 0.0450 0.0480 0.0560 0.0580 0.0580 0.0570 Min: 0.0280 Max: 0.0580 Avg: 0.0462 ~~~~~~~~~~~~ Case 7 ~~~~~~~~~~~~ Times: 0.0290 0.0270 0.0350 0.0410 0.0430 0.0470 0.0540 0.0540 0.0550 0.0550 Min: 0.0270 Max: 0.0550 Avg: 0.044 0
Tuyên bố tiếng vang PHPCâu lệnh echo có thể được sử dụng có hoặc không có dấu ngoặc đơn. echo hoặc Case 1: $array[] = something; Case 2: array_push($array, $value); Case 3: array_push($array, $value1, $value2, $value3 [...]); $values are definied Case 4: array_push($array, $value1, $value2, $value3 [...]); $values are definied, when $array is not empty Case 5: Case1 + Case 3 Case 6: Result array contains some value (Case 4) Case 7: Result array contains same value as the push array (Case 4) ----------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~ Case 1 ~~~~~~~~~~~~ Times: 0.0310 0.0300 0.0290 0.0340 0.0400 0.0440 0.0480 0.0550 0.0570 0.0570 Min: 0.0290 Max: 0.0570 Avg: 0.0425 ~~~~~~~~~~~~ Case 2 ~~~~~~~~~~~~ Times: 0.3890 0.3850 0.3770 0.4110 0.4020 0.3980 0.4020 0.4060 0.4130 0.4200 Min: 0.3770 Max: 0.4200 Avg: 0.4003 ~~~~~~~~~~~~ Case 3 ~~~~~~~~~~~~ Times: 0.0200 0.0220 0.0240 0.0340 0.0360 0.0410 0.0460 0.0500 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0377 ~~~~~~~~~~~~ Case 4 ~~~~~~~~~~~~ Times: 0.0200 0.0250 0.0230 0.0260 0.0330 0.0390 0.0460 0.0510 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0367 ~~~~~~~~~~~~ Case 5 ~~~~~~~~~~~~ Times: 0.0260 0.0250 0.0370 0.0360 0.0390 0.0440 0.0510 0.0520 0.0530 0.0560 Min: 0.0250 Max: 0.0560 Avg: 0.0419 ~~~~~~~~~~~~ Case 6 ~~~~~~~~~~~~ Times: 0.0340 0.0280 0.0370 0.0410 0.0450 0.0480 0.0560 0.0580 0.0580 0.0570 Min: 0.0280 Max: 0.0580 Avg: 0.0462 ~~~~~~~~~~~~ Case 7 ~~~~~~~~~~~~ Times: 0.0290 0.0270 0.0350 0.0410 0.0430 0.0470 0.0540 0.0540 0.0550 0.0550 Min: 0.0270 Max: 0.0550 Avg: 0.044 04 Hiển thị văn bản Ví dụ sau đây cho thấy cách xuất văn bản bằng lệnh Case 1: $array[] = something; Case 2: array_push($array, $value); Case 3: array_push($array, $value1, $value2, $value3 [...]); $values are definied Case 4: array_push($array, $value1, $value2, $value3 [...]); $values are definied, when $array is not empty Case 5: Case1 + Case 3 Case 6: Result array contains some value (Case 4) Case 7: Result array contains same value as the push array (Case 4) ----------------------------------------------------------------------------------------------------------- ~~~~~~~~~~~~ Case 1 ~~~~~~~~~~~~ Times: 0.0310 0.0300 0.0290 0.0340 0.0400 0.0440 0.0480 0.0550 0.0570 0.0570 Min: 0.0290 Max: 0.0570 Avg: 0.0425 ~~~~~~~~~~~~ Case 2 ~~~~~~~~~~~~ Times: 0.3890 0.3850 0.3770 0.4110 0.4020 0.3980 0.4020 0.4060 0.4130 0.4200 Min: 0.3770 Max: 0.4200 Avg: 0.4003 ~~~~~~~~~~~~ Case 3 ~~~~~~~~~~~~ Times: 0.0200 0.0220 0.0240 0.0340 0.0360 0.0410 0.0460 0.0500 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0377 ~~~~~~~~~~~~ Case 4 ~~~~~~~~~~~~ Times: 0.0200 0.0250 0.0230 0.0260 0.0330 0.0390 0.0460 0.0510 0.0520 0.0520 Min: 0.0200 Max: 0.0520 Avg: 0.0367 ~~~~~~~~~~~~ Case 5 ~~~~~~~~~~~~ Times: 0.0260 0.0250 0.0370 0.0360 0.0390 0.0440 0.0510 0.0520 0.0530 0.0560 Min: 0.0250 Max: 0.0560 Avg: 0.0419 ~~~~~~~~~~~~ Case 6 ~~~~~~~~~~~~ Times: 0.0340 0.0280 0.0370 0.0410 0.0450 0.0480 0.0560 0.0580 0.0580 0.0570 Min: 0.0280 Max: 0.0580 Avg: 0.0462 ~~~~~~~~~~~~ Case 7 ~~~~~~~~~~~~ Times: 0.0290 0.0270 0.0350 0.0410 0.0430 0.0470 0.0540 0.0540 0.0550 0.0550 Min: 0.0270 Max: 0.0550 Avg: 0.044 0 (chú ý rằng văn bản có thể chứa đánh dấu HTML) Đầu ra của mã PHP sau đây sẽ là gì? MỘT). 4. 5 b). 7 C). 3. 5 Đ). Lỗi
1 câu trả lờiĐã trả lời bởi Khách vào 2021-06-27 08. 13. 44. Bình chọn 0. 4. 5 Bạn có thể sử dụng số trong một tên biến Tham gia nhóm Telegram Trả lời câu hỏi nàyTên. E-mail. Câu trả lời. Tổng của (3+1)Gửi
Điều gì sẽ là đầu ra của mã PHP sau đây |