ลบอักขระหนึ่งตัวจากด้านหลังของสตริงใน PHP
<?php
$string = "abcdef";
$new_string = substr($string, 0, -1); // ตัดอักขระตัวสุดท้ายออก
echo $new_string; // แสดงผลลัพธ์: abcde
?>
<?php
$string = "abcdef";
$new_string = substr($string, 0, -1); // ตัดอักขระตัวสุดท้ายออก
echo $new_string; // แสดงผลลัพธ์: abcde
?>
<?php
$string = "Hello World";
$lastChar = substr($string, -1);
echo $lastChar; // แสดงผล: d
?>