<?php
function func($x, $y) {
echo " until change: $x, $y"."\n";
$num=$x;
$x=$y;
$y=$num;
echo "result: $x, $y";
}
func(2,1);
\\ result-- until change: 2----1, result:1-----2
<?php
function numbers ($x) {
if ($x > 0) {
echo "number is positive";
} else if ($x == 0) {
echo "number is zero";
} else {
echo " number is negative";
}
}
echo numbers(256); \\ result-- number is positive
echo numbers(0); \\ result-- number is zero
echo numbers(-123); result-- number is negative
<?php
function code($code) {
$x=strlen($code);
if ($x == 4) {
echo "true";
} else if ($x==6) {
echo "true";
} else {
echo "false"
}
}
echo (code(1234)); \\result-true
echo (code(a4b56r)); \\result-true
echo (code(t674rhedbt8w39); \\result-false
<?php
function number($x) {
if ($x % 2) {
echo " even";
} else {
echo "odd";
}
echo (number(100)); \\result- even
echo (number(23));\\ result- odd
}
<?php
function beautiful($o) {
return substr_count($o, 010);
}
print_r (beautiful(0100100100100100111010101001011010); //output- 6
<?php
function calculatescore($x) {
return [
substr_count($x, 'Y'), //substr_count-Counts how many times this data is given
substr_count($x, 'O'),
substr_count($x, 'U')
];
}
print_r (calculatescore("YOU")); // 1,1,1
print_r (calculatescore("YYOOUU)); //2,2,2
print_r (calculatescore("UUUOOYYYY)); //3,2,4
function getExtension($file){
$exts = [];
foreach($file as $f){
$info = pathinfo($f);
//print_r($info);
$exts []= $info['extension'];
}
return $exts;
};
print_r(getExtension(["ruby.rb", "cplusplus.cpp", "python.py", "javascript.js"]));
print_r(getExtension(["code.html", "code.css"]));