Ayyukan gama gari a cikin PHP- Kashi na 1

Ayyukan sarrafa igiyoyi

strlen(): Yana mayar da tsayin kirtani.

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

strtoupper(): Yana canza kirtani zuwa babban harafi.

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

strtolower(): Yana canza kirtani zuwa ƙananan haruffa.

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

substr(): Yana fitar da wani yanki na kirtani bisa tushen farawa da tsayi.

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

 

Ayyukan magudin lamba

intval(): Yana canza ƙima zuwa lamba.

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

loatval(): Yana canza ƙima zuwa mai iyo.

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

number_format(): Yana tsara lamba tare da dubban masu raba.

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

 

Ayyukan sarrafa tsararru

count(): Yana ƙidaya adadin abubuwan da ke cikin tsararru.

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

array_push(): Yana ƙara wani kashi zuwa ƙarshen tsararru.

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

array_pop(): Yana cirewa da dawo da kashi na ƙarshe na tsararru.

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

 

Waɗannan ƙananan misalan ayyuka ne da aka saba amfani da su a cikin PHP. Akwai ƙarin ayyuka da yawa don ayyuka daban-daban. Kuna iya bincika takaddun PHP don ƙarin cikakkun bayanai akan ayyuka daban-daban da amfaninsu.