Ayyukan gama gari a cikin PHP- Kashi na 2

isset() aiki

Yana bincika idan an saita ma'auni kuma yana da ƙima.

$name = "John";  
if(isset($name)) {  
    echo "Variable 'name' is set.";  
} else {  
    echo "Variable 'name' is not set.";  
}  

 

empty() aiki

Yana bincika idan mai canzawa ba komai bane ko babu.

$email = "";  
if(empty($email)) {  
    echo "Email is not provided.";  
} else {  
    echo "Email is provided.";  
}  

 

exit() ko aiki die()

Yana dakatar da aiwatar da shirin kuma yana nuna saƙo idan an buƙata.

$age = 15;  
if($age < 18) {  
    echo "You are not old enough to access.";  
    exit();  
}  
echo "Welcome to the website.";  

 

continue tsarin sarrafawa

Yana tsallake jujjuyawar madauki na yanzu kuma yana matsawa zuwa juzu'i na gaba.

for($i = 1; $i <= 10; $i++) {  
    if($i == 5) {  
        continue;  
    }  
    echo $i. " ";  
}  
// Output: 1 2 3 4 6 7 8 9 10  

 

break tsarin sarrafawa

Yana ƙare madauki ko kisa na yanzu.

$num = 1;  
while(true) {  
    echo $num. " ";  
    if($num == 5) {  
        break;  
    }  
    $num++;  
}  
// Output: 1 2 3 4 5  

 

var_dump() aiki

Ana amfani da aiki don nuna cikakken bayani game da maɓalli ko ƙima. Yana ba ku damar ganin nau'in bayanai, ƙima, da girman ma'auni.

$number = 10;  
$string = "Hello";  
$array = [1, 2, 3];  
  
var_dump($number); // int(10)  
var_dump($string); // string(5) "Hello"  
var_dump($array); // array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }  

 

print() aiki

Ana amfani da aiki don nuna ƙima akan allon. Yana kama da echo, amma yana dawo da ƙimar 1 idan yayi nasara.

$name = "John";  
  
print "Hello, ". $name; // Hello, John  

 

print_r() aiki

Ana amfani da aiki don nuna bayani game da maɓalli ko tsararru a tsarin da za a iya karantawa. Yana da amfani lokacin da kake son ganin tsari da ƙimar tsararru.

$array = [1, 2, 3];  
  
print_r($array);  
/* Output:  
Array  
(  
    [0] => 1  
    [1] => 2  
    [2] => 3  
)  
*/  

 

Lưu ı: Ana amfani da var_dump, print da print_r ayyuka akai-akai don dalilai na gyara kuskure, saboda ba sa mayar da ƙima kuma kawai suna nuna bayanai akan allon.