Skip to content

Commit 6fbf266

Browse files
committed
adding more and update
1 parent 53395da commit 6fbf266

7 files changed

+93
-0
lines changed

array_flip.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
// array_flip
3+
$names = [
4+
"reza",
5+
"hamid",
6+
"ali",
7+
"farzad",
8+
"abbas",
9+
"amirreza",
10+
"far"
11+
];
12+
$names = array_flip($names);
13+
print_r($names);

call_user_func_array.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
// call_user_func_array
3+
function my_function($a, $b) {
4+
return $a + $b;
5+
}
6+
var_dump( call_user_func_array("my_function", [1, 2]) );
7+
var_dump( call_user_func_array("my_function", [1, 2, 3, 4, 5]) );
8+
9+
"my_function"(1, 2);
10+
11+
$params = [1, 2];
12+
"my_function"($params[0], $params[1]);

file.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, World!Hi!

function.php

+30
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,33 @@ function my($number1, $number2, $fn) {
5858
};
5959
$sayHey("Rey");
6060
unset($sayHey);
61+
62+
function sum(...$numbers) {
63+
$sum = 0;
64+
foreach ($numbers as $number) {
65+
$sum += $number;
66+
}
67+
return $sum;
68+
}
69+
print sum(1, 2, 3, 4)."\n";
70+
71+
function sum2($numbers) {
72+
$sum = 0;
73+
foreach ($numbers as $number) {
74+
$sum += $number;
75+
}
76+
return $sum;
77+
}
78+
print sum2([1, 2, 3, 4])."\n";
79+
// print sum([1, 2, 3, 4])."\n";
80+
81+
82+
function func($a, $b, $c, int ...$numbers) {
83+
$sum = 0;
84+
foreach ($numbers as $number) {
85+
$sum += ($number + $a - $b) * $c;
86+
}
87+
return $sum;
88+
}
89+
var_dump(func(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
90+
// var_dump(func(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "hi"));

fwrite.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
// fwrite
3+
$f = fopen("file.txt", "w"); // write
4+
fwrite($f, "Hello World");
5+
fclose($f);
6+
7+
file_put_contents("file.txt", "Hello, World!");
8+
file_get_contents("file.txt");
9+
10+
11+
12+
file_put_contents("file.txt", "Hi!", FILE_APPEND);
13+
14+
file_put_contents("music.mp3", file_get_contents("https://kharatha.com/Heyf2.mp3"));

phpinfo.php

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
phpinfo();

strrpos.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
// strrpos
3+
$str = "Hello World o o o o o";
4+
$a = strrpos($str, "o");
5+
var_dump(strlen($str));
6+
var_dump($a);
7+
8+
// offset
9+
$foo = "0123456789a123456789b123456789c";
10+
11+
// Looking for '0' from the 0th byte (from the beginning)
12+
var_dump(strrpos($foo, '0', 0));
13+
// int(0)
14+
15+
// Looking for '0' from the 1st byte (after byte "0")
16+
var_dump(strrpos($foo, '0', 1));
17+
// bool(false)
18+
19+
// Looking for '7' from the 21th byte (after byte 20)
20+
var_dump(strrpos($foo, '7', 20));
21+
// int(27)

0 commit comments

Comments
 (0)