http://javascript.info/ tutorial/browser-window- properties-and-methods
Example JS http://www.tutorialspoint.com/javascript/javascript_objects.htm
Try the following example.<html> <head> <title>User-defined objects</title> <script type="text/javascript"> // Define a function which will work as a method function addPrice(amount){ with(this){ price = amount; } } function book(title, author){ this.title = title; this.author = author; this.price = 0; this.addPrice = addPrice; // Assign that method as property. } </script> </head> <body> <script type="text/javascript"> var myBook = new book("Perl", "Mohtashim"); myBook.addPrice(100); document.write("Book title is : " + myBook.title + "<br>"); document.write("Book author is : " + myBook.author + "<br>"); document.write("Book price is : " + myBook.price + "<br>"); </script> </body> </html>Output
Book title is : Perl Book author is : Mohtashim Book price is : 100
http://www.plus2net.com/html_ tutorial/button-linking.php
Passing Arguments by Reference
It
is possible to pass arguments to functions by reference. This means
that a reference to the variable is manipulated by the function rather
than a copy of the variable's value.
Any
changes made to an argument in these cases will change the value of the
original variable. You can pass an argument by reference by adding an
ampersand to the variable name in either the function call or the
function definition.
Following example depicts both the cases.
<html> <head> <title>Passing Argument by Reference</title> </head> <body> <?php function addFive($num) { $num += 5; } function addSix(&$num) { $num += 6; } $orignum = 10; addFive( $orignum ); echo "Original Value is $orignum<br />"; addSix( $orignum ); echo "Original Value is $orignum<br />"; ?> </body> </html>
This will display following result:
Original Value is 10 Original Value is 16
When do we pass arguments by reference or pointer?
In C++, variables are passed by reference due to following reasons:
1) To modify local variables of the caller function: A
reference (or pointer) allows called function to modify a local
variable of the caller function. For example, consider the following
example program where fun() is able to modify local variable x of main().
void
fun(
int
&x) {
x = 20;
}
int
main() {
int
x = 10;
fun(x);
cout<<
"New value of x is "
<<x;
return
0;
}
Output:
New value of x is 20
In C++, variables are passed by reference due to following reasons:
1) To modify local variables of the caller function: A
reference (or pointer) allows called function to modify a local
variable of the caller function. For example, consider the following
example program where fun() is able to modify local variable x of main().
void fun( int &x) { x = 20; } int main() { int x = 10; fun(x); cout<< "New value of x is " <<x; return 0; } |
Output:
New value of x is 20
New value of x is 20
PHP Functions retruning value
A function can return a value using the return statement
in conjunction with a value or object. return stops the execution of
the function and sends the value back to the calling code.
You can return more than one value from a function using return array(1,2,3,4).
Following
example takes two integer parameters and add them together and then
returns their sum to the calling program. Note that return keyword is used to return a value from a function.
<html> <head> <title>Writing PHP Function which returns value</title> </head> <body> <?php function addFunction($num1, $num2) { $sum = $num1 + $num2; return $sum; } $return_value = addFunction(10, 20); echo "Returned value from the function : $return_value"; ?> </body> </html>
This will display following result:
Returned value from the function : 30
http://www.trans4mind.com/search
......................................................................................................
In javascript, you can use either single (') or double (") quotes and they behave the same. In php, it is different. Double quotes and single quotes aren't exactly the same.
In the above, using double quotes, the variable $something is evaluated within the quotes and the result isn't what is expected: the variable is evaluated to Oh something. Variables, but not functions or constants, are evaluated even when enclosed in double quotes.$something="Oh something";
echo "My answer is $something.<br>";
//result is: My answer is Oh something
When single quotes are used, as above, the variable isn't evaluated and is printed on the screen literally as $something.echo 'My answer is $something.<br>';
//result is: My answer is $something.
Escaping with the backslash \
The backslash character (\) can be used to escape quotes and variables. The next example repeats the idea that things are evaluated within double quotes:$something="Oh something!";
echo "My answer is $something";
//result: My answer is Oh something!
So nothing new here, just a reminder. Next
we use the backslash to escape the variable $something and also the double quotes around
"is":
======================================
echo "<br>";echo "My answer \"is\" \$something";
//result: My answer "is" $something
mysql_fetch_row ::Return row as aan enumrated array and each line contain a unique ID .example.
$result=mysql_query($query);
while($row=mysql_fetch_row($result))
{
print "$row[0]";
print "$row[1]";
print "$row[2]";
}
mysql_fetch_array ::Return row as anassociative or an enumrated array or both which is default .you can refer to outputs as databases fieldname rather then number .example.
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
print "$row['name']";
print "$row['address']";
print "$row['city']";
}
mysql_fetch_object :: it return as an object on the place of array.
$result=mysql_query($query);
while($row=mysql_fetch_object($result))
{
print "$row->name";
print "$row->address";
print "$row->city";
}
.............................................................................................................................................
form.php
PHP Code:
<input type="file" name="image[]">
<input type="file" name="image[]">
// array
image[] is called as
$_FILES['image']
PHP Code:
// array
image[] is called as
$_FILES['image']
if(!empty($_FILES['image']['name'])){
foreach($_FILES['image']['name'] as $k => $v){
print '$_FILES["image"]["name"]["'.$k.'"] = '.$v;
}
}
o/p
PHP Code:
Array
(
[image] => Array
(
[name] => Array
(
[0] =>
[1] =>
)
[type] => Array
(
[0] =>
[1] =>
)
[tmp_name] => Array
(
[0] =>
[1] =>
)
[error] => Array
(
[0] => 4
[1] => 4
)
[size] => Array
(
[0] => 0
[1] => 0
)
)
)
=======================================================
Multiple File Upload with PHP and MySQL
<?php
if(isset($_FILES['files'])){
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
if($file_size > 2097152){
$errors[]='File size must be less than 2 MB';
}
$query="INSERT into upload_data (`USER_ID`,`FILE_NAME`,`FILE_SIZE`,`FILE_TYPE`) VALUES('$user_id','$file_name','$file_size','$file_type'); ";
$desired_dir="user_data";
if(empty($errors)==true){
if(is_dir($desired_dir)==false){
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"user_data/".$file_name);
}else{ //rename the file if another one exist
$new_dir="user_data/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
mysql_query($query);
}else{
print_r($errors);
}
}
if(empty($error)){
echo "Success";
}
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="files[]" multiple="" />
<input type="submit"/>
</form>
------------------------------------------------------------------------------------------
http://forum.codecall.net/forum/158-php-tutorials/ BEST PHP TUTS
https://www.google.co.in/search?q=php+logical+problems
MULTI–DIMENSIONAL ARRAYS
Please note that the material on this website is not intended to be exhaustive.
This is intended as a summary and supplementary material.
A 2 dimensional array consists of rows and columns.Figure 082: Two-dimensional Array
Figure 083: Two-dimensional Array Storage
Figure 084: Three-dimensional Array
There are no review questions for this reading assignment.
$this
with $this you can call functions and variables of a class. It means this class or this document. In some programming language we call it me. Take a look at this code
class Example { public $name = "papabear"; public $color; function Sample() { echo "This is an example"; } function SayName() { echo $this->name; } function saySample() { $this->Sample(); } } $obj = new Example(); $obj->SayName(); echo "<br/>"; $obj->saySample();
output :
Quote
papabear
This is an example
to be more clear.. $this applies to a class that we are IN. here's another example
class Example { public $name = "papabear"; public $color; function Sample() { echo "This is an example"; } function SayName() { $name = "alleo"; echo $this->name; } function saySample() { $this->Sample(); } } $obj = new Example(); $obj->SayName();
Output :
papabear
Take a look at the
function SayName() { $name = "alleo"; echo $this->name; }
have you noticed the difference? You can't use a class property or variable if you didn't call them using $this
$name and $this->name is different from each other.. $name is a variable or a property or the function while the $this->name is a global variable/property, please don't be confused with that. I know it's confusing but please.. bare with me
That's all for today's tutorial.. Thanks for your time, if you have some questions and found some error in my tutorial please feel free to reply.. I'm still learning this things and wants to share what I've learned.. I'm posting tutorials to learn from critics also see ya soon
More Powers
Papabear
-------------------------------------------------------------------------
PHP OOP Tutorial from beginner to advance - (Abstract Classes - Part 6) | ||||
PHP OOP Tutorial from beginner to advance - (Encapsulation - Part 9) |
No comments:
Post a Comment