3v4l.org

run code in 300+ PHP versions simultaneously
<?php function format(&$item) { $item = strtoupper($item) . '.'; return $item; //hàm này trả về item được in hoa } $shopping = array("fish", "bread", "eggs", "jelly", "apples"); array_walk($shopping, "format"); //hàm array_walk nhận 2 tham số, hai tham số này ngược với array_map. $shopping = sort($shopping); //tricky ở chỗ này, vì hàm sort() trả về boolean nên sẽ là 1 nếu print hay echo. echo $shopping[1]; //shopping không còn là array nữa nên đâu có trả về cái giề, vãi thật. /*--------------------------------------*/ echo "------------code sửa một tí, ra kết quả khác--------"; //code dưới copy câu trên chỉ sửa một tí $shopping = array("fish", "bread", "eggs", "jelly", "apples"); array_walk($shopping, "format"); //hàm array_walk nhận 2 tham số, hai tham số này ngược với array_map. sort($shopping); // mình không đặt biến để hứng kết quả từ hàm sort, vì nếu không nó sẽ trả về true/1 echo $shopping[1]; //giờ thì ra bread viết hoa cho mà xem, vì hàm sort sắp xếp theo abcd/ //by @vuong
Output for 8.3.0 - 8.3.4, 8.3.6
Warning: Trying to access array offset on true in /in/rt1LS on line 13 ------------code sửa một tí, ra kết quả khác--------BREAD.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Trying to access array offset on true in /in/rt1LS on line 13 ------------code sửa một tí, ra kết quả khác--------BREAD.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Warning: Trying to access array offset on value of type bool in /in/rt1LS on line 13 ------------code sửa một tí, ra kết quả khác--------BREAD.
Output for 7.4.0 - 7.4.33
Notice: Trying to access array offset on value of type bool in /in/rt1LS on line 13 ------------code sửa một tí, ra kết quả khác--------BREAD.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
------------code sửa một tí, ra kết quả khác--------BREAD.

preferences:
176.56 ms | 402 KiB | 191 Q