1 / 8

MỘT SỐ HÀM MẢNG TRONG PHP

MỘT SỐ HÀM MẢNG TRONG PHP. GVHD : NGUYỄN PHẠM THẾ VINH. Thực hiện: Tổ 3. Hàm sắp xếp - Sắp xếp các phần tử trong mảng theo thứ tự tăng dần. - Cú pháp: sort ($mang); Ví dụ: $mang=array(1,3,6,2,"a","c","b"); sort($mang); print_r($mang); /*output:

veta
Download Presentation

MỘT SỐ HÀM MẢNG TRONG PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MỘT SỐ HÀM MẢNG TRONG PHP GVHD: NGUYỄN PHẠM THẾ VINH Thực hiện: Tổ 3

  2. Hàm sắp xếp - Sắp xếp các phần tử trong mảng theo thứ tự tăng dần. - Cú pháp: sort ($mang); Ví dụ: $mang=array(1,3,6,2,"a","c","b"); sort($mang); print_r($mang); /*output: $mang=array (a, b, c, 1, 2, 3, 6)

  3. Hàm gộp mảng - Nối 2 mảng thành 1 mảng lớn. - Cú pháp: array_merge ($mang1, $mang2); Ví dụ: $mang1=array(1,2,4,5,7); $mang2=array("a","b","c"); $mangth=array_merge($mang1, $mang2); print_r($mangth); /*output: $mangth=array(1,2,4,5,7,"a","b","c")

  4. Hàm tách mảng - Tách ra 1 mảng con từ mảng lớn tại vị trí và số phần tử chỉ định. - Cú pháp: array_slice ($mang, vị trí tách, số lượng tách); Ví dụ: $mang=array(1,2,4,5,6,"a","b","c"); $mang2=array_slice($mang,5, 3); print_r($mang2); /*output: $mang2=array(“a”, “b”, “c”)

  5. Hàm tìm kiếm - Kiểm tra sự tồn tại của một phần tử trong mảng. - Kết quả trả về là vị trí của phần tử đầu tiên được tìm thấy. Ngược lại trả về False. - Cú pháp: array_search (giá trị tìm, $mảng); Ví dụ: $mang=array(1,2,4,5,6,"a","b","c"); $kq=array_search("b",$mang); echo $kq; /*output: $kq=6

  6. Hàm đếm • Trả về số phần tử trong mảng. • Cú pháp: count ($mang); Ví dụ: $mang=array(1,2,4,5,6,"a","b","c"); $kq=count($mang); echo $kq; /*output: $kq=8;

  7. Hàm Array_unique () - Loại bỏ các giá trị trùng nhau. Chỉ lấy giá trị đầu tiên nếu có nhiều giá trị trùng nhau trong mảng. - Cú pháp: array_unique ($mang); - Ví dụ $a=array("a"=>"Cat","b"=>"Dog","c"=>"Cat"); print_r(array_unique($a));/* Output: $a=array (“Cat”, “Dog”);

  8. Hàm array_push () -Thêm một hoặc nhiều phần tử vào cuối một mảng có sẵn. - Cú pháp: array_push($mang, giá trị1, giá trị 2,…, giá trị n); Ví dụ $mang = array(1,4,7,2); array_push($mang, 5); print_r($mang); /* Output: $mang=array (1,4,7,2,5);

More Related