Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ad5acd3

Browse files
module 6
1 parent 759968f commit ad5acd3

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed

‎array.php‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
// array 3 types
4+
5+
// 1. indexed array.
6+
// 2. associative array.
7+
// 3. multi dimenstion array.
8+
9+
// ---> index array [], array()
10+
$data_types = array('number','integer','string','double','float'); //index array
11+
12+
// print_r($data_types[4]);
13+
14+
// ----> associative array
15+
$data_type = [
16+
'string' => 'Deepak',
17+
'integer' => 24,
18+
'float' => 6.1,
19+
"boolen" => true
20+
];
21+
22+
// print_r($data_type['float']);
23+
// foreach($data_type as $key => $value){
24+
25+
// }
26+
27+
// ----> Multi dim array
28+
$details = [
29+
'name' => 'Deepak',
30+
'age' => 24,
31+
'height' => 6.1,
32+
"is_good" => true,
33+
"address" => [
34+
'city' => 'delhi',
35+
'area' => 'cp',
36+
'pincode' => 110057,
37+
'flat_details' => [
38+
'xyz',
39+
'abc'
40+
]
41+
]
42+
];
43+
print_r($details['address']["flat_details"][1]);
44+
45+
46+
47+
?>

‎arru_def.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
function toPrintSerice( int $to, int $from = 0){ /// default value arrguments they from right side
4+
$ser = []; //null array
5+
for ($i=$from; $i < $to+1; $i++) {
6+
# code...
7+
array_push($ser,$i);
8+
}
9+
return $ser;
10+
}
11+
12+
$seq = toPrintSerice(10,-5);
13+
14+
print_r($seq);
15+
16+
?>

‎call_by_reference.php‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
function increment_refer(&$y){
4+
$y++;
5+
return $y;
6+
}
7+
8+
function inrement($y){
9+
$y++;
10+
return $y;
11+
}
12+
13+
$x = 1;
14+
15+
$z = increment_refer($x);
16+
print_r("old variable --- >$x");
17+
print_r("\n");
18+
print_r("new variable --- >$z"); // 1
19+
20+
21+
?>

‎call_by_value.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
function myFunction($fruit){
4+
$fruits = ['apple', 'mango', 'banana', 'orange','lichi'];
5+
if(in_array($fruit,$fruits)){ //0,1
6+
return 'Yes, '.$fruit.' is fruit';
7+
}else{
8+
return "No given item is not fruit";
9+
}
10+
}
11+
12+
print_r(myFunction('tomato'));
13+
?>

‎strings.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
// types of string def
4+
// 1. single quoted
5+
// 2. double quoted
6+
// 3. heredoc syntax
7+
8+
$string = 'this is deepak ' . "\n". 'lkhdadh';
9+
10+
$str = "this is deepak $string\n";
11+
12+
// heredoc
13+
$strr = <<<Demo
14+
this is deepak..
15+
i m from delhi
16+
17+
Demo;
18+
19+
print_r($strr);
20+
21+
//php buil in functions
22+
// strlen, str_replace, strtoupper, strtolower, ....
23+
24+
25+
?>

‎var_argu.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
// 1 to n ..
4+
5+
// function functionName(...$number){
6+
// //code to execute...
7+
// }
8+
9+
// we have write a program to add n numbers?
10+
11+
function add_nubmers(...$numbers){
12+
$sum = 0;
13+
foreach($numbers as $number){
14+
$sum += $number;
15+
}
16+
return $sum;
17+
}
18+
19+
$sum = add_nubmers(1,23,43,12,5454,464,1);
20+
21+
// print_r($sum);
22+
23+
// Write a program to return names in an array ?
24+
25+
function names_array(...$names){
26+
$appended_names = [];
27+
$return_string = "";
28+
foreach($names as $name){
29+
array_push($appended_names,$name);
30+
$return_string .= "$name, ";
31+
}
32+
return $appended_names;
33+
}
34+
35+
print_r(names_array('Nitin','Shikha','Naveen','Raju'));
36+
37+
?>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /