Fungsi Umum ing PHP- Part 1

Fungsi manipulasi string

strlen(): Ngasilake dawa senar.

$str = "hello";  
echo strtoupper($str); // Output: HELLO  

strtoupper(): Ngonversi string menyang huruf gedhe.

$str = "hello";  
echo strtoupper($str); // Output: HELLO  

strtolower(): Ngonversi string dadi huruf cilik.

$str = "WORLD";  
echo strtolower($str); // Output: world  

substr(): Extracts bagean saka senar adhedhasar posisi wiwitan lan dawa.

$str = "Hello, world!";  
echo substr($str, 7, 5); // Output: world  

 

Fungsi manipulasi angka

intval(): Ngonversi nilai menyang integer.

$num = 10.5;  
echo intval($num); // Output: 10  

loatval(): Ngonversi nilai menyang float.

$num = "3.14";  
echo floatval($num); // Output: 3.14  

number_format(): Format nomer karo ewu pamisah.

$num = 1000;  
echo number_format($num); // Output: 1,000  

 

Fungsi manipulasi array

count(): Ngetung jumlah unsur ing larik.

$arr = [1, 2, 3, 4, 5];  
echo count($arr); // Output: 5  

array_push(): Nambahake unsur ing mburi array.

$arr = [1, 2, 3];  
array_push($arr, 4);  
print_r($arr); // Output: [1, 2, 3, 4]  

array_pop(): Mbusak lan ngasilake unsur pungkasan saka array.

$arr = [1, 2, 3, 4];  
$lastElement = array_pop($arr);  
echo $lastElement; // Output: 4  

 

Iki mung sawetara conto fungsi sing umum digunakake ing PHP. Ana akeh fungsi liyane sing kasedhiya kanggo macem-macem tugas. Sampeyan bisa njelajah dokumentasi PHP kanggo rincian liyane babagan macem-macem fungsi lan panggunaane.