Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP
PHP
  1. โปรแกรม PHP คำนวณเวลารวมจากอาร์เรย์ของเวลา

    ฟังก์ชัน strtotime สามารถใช้แปลงสตริงที่ให้มาเป็นรูปแบบเวลาได้ มาดูตัวอย่าง −ตัวอย่าง<?php $time_arr = [ 00:12:56, 10:11:12, 24:12:44, 50:51:52, 10:10:10 ]; $time = strtotime(00:00:00); $total_time = 0; foreach( $time_arr as $ele ) { $sec_time = strtotime($ele) - $time; $

  2. PHP คำนวณ Execution Time ของ Script

    ตัวอย่างโค้ด<?php $start = microtime(true); $val = 1; for ($i = 1; $i <= 1500; $i++) { $val++; } $end = microtime(true); $exec_time = $end - $start; echo The execution time of the PHP script is: $exec_time sec; ?> ผลลัพธ์The execution time of the PHP script is: 0.000123 sec คำอธิบาย m

  3. PHP ลบ Non-alphanumeric Characters จาก String

    ตัวอย่างโค้ด<?php $my_str = Thisis!@sample*on&ly)#$; $my_str = preg_replace(/[^a-z0-9]/i, , $my_str); echo The non-alphanumeric characters removed gives the string as . $my_str; ?> ผลลัพธ์The non-alphanumeric characters removed gives the string as Thisissampleonly คำอธิบาย Regex /[^a-z

  4. PHP แยก String คั่น Comma เป็น Array

    ตัวอย่างโค้ด<?php $my_string = 456,789,23, 4, 019; $my_str_arr = preg_split(/,/, $my_string); print_r($my_str_arr); $my_string = 00, 876, 5432, 1234, 0; $my_str_arr = explode(,, $my_string); print_r($my_str_arr); ?> ผลลัพธ์ 0 ) คำอธิบาย preg_split() - Regex Split (Pattern: /,/) explode()

  5. PHP ตรวจสอบจำนวนเฉพาะ (Prime Number)

    ตัวอย่างโค้ด<?php function check_prime($num) { if ($num == 1) return 0; for ($i = 2; $i <= $num / 2; $i++) { if ($num % $i == 0) return 0; } return 1; } $num = 47; $flag_val = check_prime($num); if ($flag_val == 1) echo It is a prime number; else echo It is a non-prime nu

  6. PHP ค่าเฉลี่ย N จำนวนคู่แรก

    ตัวอย่างโค้ด<?php function even_nums_avg($val) { return $val + 1; } $val = 11; echo The average of the first n natural numbers that are even is . even_nums_avg($val); ?> ผลลัพธ์The average of the first n natural numbers that are even is 12 คำอธิบายและแก้ไข ปัญหา: ฟังก์ชัน even_nums_avg

  7. PHP ตรวจสอบเลขใน Sequence

    ตัวอย่างโค้ด 0 && ($val_2 - $val_1) % $val_3 == 0) return true; return false; } $val_1 = 11; $val_2 = 99; $val_3 = 2; echo Is the number present in the sequence? ; if (contains_in_sequence($val_1, $val_2, $val_3)) { echo Yes, it is present in the sequence; } else { echo No, it is not p

  8. PHP หาตัวเลขที่หายไปใน Array

    ตัวอย่างโค้ด<?php function missing_nums($my_arr, $arr_len, $val) { sort($my_arr); $i = 0; while ($i < $val && $my_arr[$i] <= 0) $i++; $count = 0; $current_num = 1; while ($count < $val && $i < $arr_len) { if ($my_arr[$i] != $current_num) { echo $current

Total 1286 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:48/65  20-คอมพิวเตอร์/Page Goto:1 42 43 44 45 46 47 48 49 50 51 52 53 54