Tuesday, December 24, 2013

PHP Functions And their usages- learn more with @s.shivasurya

power of php
Just like real life we assign functions to be executed by passing inputs as hardwork and outcome as happiness :) by the way integrating them to programming languages functions are important tasks to be provided with input and obtain outputs in desired manner.


PHP FUNCTIONS

PHP is known For it's inbuilt power of functions.The fact is You can design your own function in php and they too can be passed with arguments to execute the corresponding statements!.And this is kn own as USER DEFINED FUNCTIONS.those functions work only when they are called from the program.defining a function in php program is easy job to run a code straight away.It is very helpful when we run a large files in a simpler manner.programmers can feel easy while using functions assigning to different functions and determining the way to be executed while the code runs on the machine.Usage of functions reduce the time and coding lines.Just like we could pass arguments and run the codes to attain desirable results.

For the beginners may fing difficult with moving through the functions of PHP.but when you integrate yourselves,mostly You will find out functions to execute in better manner & you could manage the codings efficiently and fix the bugs in all possible ways.it will be very helpful while arranging in a squence and calling a function and execution.

let's have a small example here about the simple program in php:

this is how beginners write their coding:

<?php
echo "shivasurya.s is a programmer & skilled person.<br>";
echo "boyka is a programmer & skilled person.<br>";
echo "sharukh khan is a programmer & skilled person.<br>";
echo "muzzamil musthafa is a programmer & skilled person.<br>";
?>

this is how experienced programmers write their coding:

<?php
function familyName($fname)
{
echo "$fname is a programmer & skilled person.<br>";
}

familyName("shivasurya.s");
familyName("boyka");
familyName("shahrukh khan");
familyName("muzzamil musthafa");

?>
in this example both generates same results, but the usage of functions plays a vital role and helps to fix the bug in the code easier and identify.This may also Reduce Your coding lines and makes the program to work efficient manner.

Let's see a real life Example here:


A small snippet to Insert Database with functions :

Here we could assume that we can insert the database with consumers data after complete validation and cleaning  :P :P

<?php
function insertdb_user($name,$company,$age,$website,$income)
{
 $update=mysql_query('insert into users (name,comapny,age,website,income)  values("$name","$company","$age","$website","$income")');
 echo "Updated successfully here.";
}

insertdb_user($userpostedname,$userpostedcompany,$userpostedage,
$userpostedwebsite,$userpostedincome
);

?>

here programmer can use many arguments as their wish and create many functions of their own and execute to obtain desired results.apart form the user defined functions ,there a huge amount of PHP inbuilt functions You can read it in Documentation or Manuals of PHP websites.

here is a small example of PHP inbuilt function date()  :

<?php

// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the


// Mountain Standard Time (MST) Time Zone


$today date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm


$today date("m.d.y");                         // 03.10.01


$today date("j, n, Y");                       // 10, 3, 2001


$today date("Ymd");                           // 20010310


$today date('h-i-s, j-m-y, it is w Day');     // 05-16-18, 10-03-01, 1631 1618 6 Satpm01


$today date('\i\t \i\s \t\h\e jS \d\a\y.');   // it is the 10th day.


$today date("D M j G:i:s T Y");               // Sat Mar 10 17:16:18 MST 2001


$today date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:18 m is month


$today date("H:i:s");                         // 17:16:18


$today date("Y-m-d H:i:s");                   // 2001-03-10 17:16:18 (the MySQL DATETIME format)


?>

here in the above pre defined functions are already built inside PHP ,we just call them with suitable arguments and they provide us the correct,desired results in the form of html codes and they are displayed in browsers.thus we can learn more function using the MANUAL website by PHP. & soon you too can create your own functions in PHP and implement in your php websites!



yup!You guys Gone through functions in this tutorial! functions are quite easy according to me,they are easy to handle and maintain huge set of codes and makes the task simpler and easier!

human errors are common!lets make it error free by helping one another!.so,
feel free to comment below!

2 comments:

Anonymous said...

nice ! thanks for the post gave a clear idea !

Sonali Bhaumik said...

This video explains the full proof method to root Samsung Galaxy S Duos 2

Plase like my videos and subscribe to my youtube channel.

https://www.youtube.com/watch?v=UFp7XT4A5WQ

Post a Comment

feel free to post your comments! Don't Spam here!