Untitled
<?php //question 1 calculate the sum of even numbers // $z=[6,7,9,4,5,8]; // $total=0; // foreach($z as $zaki){ // if($zaki%2==0){ // $total+=$zaki; // } // } // echo "the sum is $total"; //question 2 sum up the two arrays // $z=[6,7,9,4,5,8]; // $h=[6,7,9,4,5,8]; // $zaki=[]; // for($i=0;$i<=5;$i++){ // $zaki[$i]=$z[$i]+$h[$i]; // } // print_r($zaki); // function to calculate the sum of two absolute values // function sum_of_abs($x){ // if($x<0) // return $x*-1; // else // return $x; // } // $sum=sum_of_abs(-5)+sum_of_abs(-6); // echo $sum; // question 4 print this loop // for($r=1;$r<=5;$r++){ // for($c=1;$c<=$r;$c++){ // echo "X"; // } // echo "<BR>"; // } //question 5 print the same loop but in row 2 must be 22 and row four is 4444 for($r=1;$r<=5;$r++){ for($c=1;$c<=$r;$c++){ if($r%2==0) echo "$r"; else echo "X"; } echo "<BR>"; } // so2al array // so2al pattern // so2al function // dool written code // wel ba2y hayb2a 3ala kolo bel datbase connection ?>
Leave a Comment