Posts

Showing posts from September, 2012

PHP foreach statement

PHP foreach statement works on PHP array by which we can reach every elements of an array. For example, we have an array like $array(10,20,30,40), we want to print each element of that array. In this kind of case that means in PHP array we use PHP foreach statement. Now take a look at the structure of PHP foreach statement. foreach($array as $value) { code to be executed; } In the foreach statement at first we use the actual array and then we use a temporary variable which is used to store the array elements. foreach statement example Now I am trying to provide an example. Think that we have an array that contains number 1,2,3,4,5 . So now try to print each array value using PHP. <?php $number=array(1,2,3,4,5); foreach($number as $value ) {     echo $value;     } ?> In the above code we just print the each value of this array. Now we try to print something based on condition. So now take a look at the example. <?php $number=array(1,2,3,4,5); foreach($number as $value ) {     i

PHP continue statement

PHP continue statement and break statement are identical but the only difference is PHP continue statement just skip the current iteration and continue execute other iteration inside loop. We can use continue statement in PHP iteration statement such as for loop, while loop and do-while loop.  We can define PHP continue statement by using if statement such as if(condition) continue;   If the condition is true then the continue statement is executed.  Now we consider an example to understand the PHP continue statement. PHP continue statement example: <?php for($count=0; $count<=10; $count++) { if($count==5) continue; echo $count; } In this example after if condition we use continue statement. So this program not print 5 because for continue statement. The output look like this where 5 is missing 1234678910

PHP break statement

We use two jump statement in PHP such as break statement and continue statement. Break means stop. So PHP break statement stop the program execution based upon condition. We use PHP break and continue statement to control the loop or program flow. PHP break and continue statement is totally different from each others. If we found PHP break statement inside a loop then the loop will stop the execution and the loop will be terminated. So we can say that if PHP break statement is available in the loop then the loop won't work by comparing specific condition. In the condition part we use if statement and then we set break statement. PHP break statement Structure: if(condition) break; In this code at first we use a condition, if the condition is true then the break statement is executed and it terminate or jump the program. PHP break statement example:  Now consider an example using PHP. In this example we use for loop but you can use break statement in any kind of loop such as while l

PHP control statements

We need to control PHP code based upon different condition for example, if the user click on the registration button, then a registration form will show to the users. To control the PHP code we use different types of PHP control statement such as if, else, for loop, break etc. PHP control statement has been broken into three types of category.  PHP selection statement PHP iteration statement PHP jump statement From those statements, using PHP selection statement we can easily select different types of PHP code based upon condition. We can divide the PHP selection statement into two parts  PHP if statement  PHP switch statement  Using PHP iteration statement we can repeat PHP code based upon condition. We can divide PHP iteration statement into three types PHP for loop PHP while loop  PHP do-while loop  Using PHP jump statement we can break PHP condition and we can jump one code snippet to another code snippet. PHP jump statements are two types PHP break statement  PHP continue statemen

ZAMPP installation

Image
In our previous tutorial we saw how to install Vertrigo web server , today I will describe how to install XAMPP web server in your local computer. XAMPP is a very powerful software that provides integrated PHP environment. To create PHP environment we need Apache, PHP, MySQL but XAMPP consolidate those three things. So follow the following steps to install ZAMPP in your computer as a server.   ZAMPP Installation Procedure I divided the installation procedure into three steps. Step 1:  We can install ZAMPP in two ways, one is manually and second one is through installer. In this section we try to install XAMPP manually. To do this, at first you need to download ZAMPP from ZAMPP DOWNLOAD . Step 2:  After downloading the file, extract the downloaded file. After extracting the file you need to choose where you want to install XAMPP such that I want to install ZAMPP in D folder. So put your extracted file in D folder. Double click on Setup_xampp.bat. Now click on xampp-control.exe, a wind

Vertrigo server installation

Image
Before installing Vertrigo server we try to know something about Vertrigo web server. Vertrigo is a software system that provides PHP environment with one step installation. This integrated software provides Apache, PHP, MySQL and PhpMyAdmin in integrated way. If you install vertrigo web server in your computer then it will creates PHP environment in your computer as a local server. So let's try to install vertrigo web server with us.  Vertrigo Server Installation Procedure: Step 1: First of all download the latest version of vertrigo web server from this link Download Vertrigo . To download the latest version click on GET THE LATEST VERSION . Step 2:  After download, double click on that file and then click next, then click on I agree. Then select the destination folder such that I select D folder like the picture. Step 3:   Install the software by clicking next. Your work is done. You will see a Vertrigo server icon in your desktop. Double click on this icon and the server wil

PHP installation

We know PHP run on server, that's why at first we need to create PHP environment in our local computer. To do this we need to install PHP and a web server. So we say that to create PHP environment we need two things  PHP (Apache) Web Server   At first we install PHP (Apache) and then we install web server. This installation process is very complex. Now a days there are various types of software provides integrated capability, that means we need to install only one software to create PHP environment. Some software are XAMPP, WAMPP, Vertrigo etc.   In our tutorial we will show you how to install XAMPP and Vertrigo in your local computer. I like vertrigo web server and though in our whole tutorial I will use Vertrigo web sever but you can use XAMPP server. XAMPP server is very useful and popular web server for the PHP developers. So guys install one software among them ( ZAMPP or Vertrigo). If you already installed PHP environment just skip this installation process. XAMPP INSTALLATI

How to try SocialAuth.NET Demo on local machine

Image
This is a simple video about steps to download and run SocialAuth.NET demo application on local machine.

PHP assignment operator

PHP assignment operator used to assign value in the variable such that we assign 10 in the variable x and we write x=10. So we can use equal to sign to assign the value. In PHP array we use => sign to assign value.

Members, __set, __get, ArrayAccess and Iterator

Lessons learned: __set() is 5 times slower than setting a member __get() + __set() is 13 times slower than incrementing a member Iterator is 4 times slower than using a member ArrayAccess is 3 times slower than setting an element in a member array ArrayAccess is 6 times slower than incrementing an element in a member array Here is the code: class test1 { public $test = null; private $_test = null; public function __set($id, $val) { $this->_test = $val; } } $start = microtime(true); $c = new test1(); for ($i=0; $i<1000000; $i++) $c->test = $i; echo number_format(microtime(true)-$start, 4)."\n"; // 0.1830s $start = microtime(true); $c = new test1(); for ($i=0; $i<1000000; $i++) $c->test2 = $i; echo number_format(microtime(true)-$start, 4)."\n"; // 0.9570s class test2 { private $_data = ['test4'=>0]; public $test3 = 0; public function __set($id, $val) { $this->_data[$id] = $val; } public function __get($id) {

Mass inserts, updates: SQLite vs MySQL (update: delayed inserts)

Lessons learned: SQLite performs inserts 8-14 times faster then InnoDB / MyISAM SQLite performs updates 4-8 times faster then InnoDB and as fast as MyISAM SQLite performs selects 2 times faster than InnoDB and 3 times slower than MyISAM SQLite requires 2.6 times less disk space than InnoDB and 1.7 times more than MyISAM Allowing null values or using synchronous=NORMAL makes inserts 5-10 percent faster in SQLite Using SQLite instead of MySQL can be a great alternative on certain architectures. Especially if you can partition the data into several SQLite databases (e.g. one database per user) and limit parallel transactions on one database. Replication, backup and restore can be done easily over the file system. The results: (MySQL 5.6.5 default config without binlog, SQLite 3.7.7, PHP 5.4.5, 2 x 1.4 GHz, disk 5400rpm) insert [s] sum [s] update [s] size [MB] JSON 1.84 1.30 2.92 2.96 CSV 1.97 2.25 3.7 2.57 SQLite (memory) 2.74 0.12 0.52 0.00 SQLite (memory, not null) 3.00 0

All About PHP array

We know what is PHP variable. In a variable we can store information. But PHP variable has some problem such as in a variable we cannot store same types of information. Variable takes same types of information as a one information. But we need to store our information separately.   For an example, we want to store different name in a variable and the code is  <?php $variable="Sharif","Rahim", "Zohn";  echo $variable; ?> This code show "Sharif","Rahim", "Zohn" but we want to show only Rahim or Zohn. That is the problem. To solve this problem we introduce PHP array. Array store same type of information and we can retrieve information separately from an array variable. To understand array we write a PHP code here. Suppose that we want to store some customers name in a variable. Take a look at the code  <?php $customers=array(“Sharif”,”Rahim”,”Karim”,”Shuvo”); echo $array[1]; ?>  

PHP for loop

PHP for loop executes repeatedly same set of instructions until a termination condition is met. Sometimes we need to work with same types of code hundred to thousands time. In that case we need to write same type of code thousands time. It is a problem. To solve this problem PHP introduce for loop where we set just upper and lower condition. PHP for loop structure:  Here is the general form of the for statement for(initialization; condition; iteration) { // Body } The for loop operates as follows:  Initialization: PHP for loop starts with initialization and initialization parts is only executed one time. Condition: It returns true or false. Condition part test the loop. If it returns true then the body of the loop is executed otherwise it exits from the loop. Iteration: It increment or decrement the counter value ( We a assume counter value which control the loop ). First the loop test the condition and then execute the body and then execute the iteration and it repeats until the co

PHP include_once statement

PHP include_once statement is very similar to PHP include statement but the only difference is include_once statement include PHP file only one time in any page. On the other hand, PHP include statement include a file many times.   Structure:   The structure of PHP include_statement is                          include_once("FileName")                              include_once("function.php") Example: Suppose that, we have three PHP file where first one has a function that print 0 to 10. Second PHP file include the first file and show the output. The third one add those two file. Now the code snippet are  first.php <?php function foo() {     for($variable=0; $variable<10;$variable++)     {         echo $variable;         echo "<br>";         } } ?> Now the second file which one show the function value and second file name is  second.php <?php include("first_code.php"); foo(); ?> Third file is third.php <?php include("c

10+ PHP project ideas for all

When I started my PHP learning, I tried to do some PHP project but I failed every time because I did not found any good direction about PHP project development . It was confusing but at last I develop my PHP skill with the help of some professional developers. Here I am just trying to help you from the scratch by which you can easily develop your PHP skill.  Why you need to do PHP projects: It creates little bit confusions in our mind why actually we do PHP project . The answer is very clear someone for money, someone for learning. I just clarify you that this blog was developed for providing education on PHP not to hire professional. Here I discuss some points which is the key benefits that you will acquire by doing PHP projects.  We do PHP projects to develop our PHP skill that means we want to be a professional in this area.  Wanting to implement our basic knowledge on PHP by doing some practical projects. For example, you think that you completed all basic php tutorials but it is n

JQuery Bind v/s Live v/s Delegate v/s On comparison matrix

Image
Bind Live Delegate On Min version required 1.0  1.3 1.4.2 1.5 Recommended No Absolute No Yes Of course Yes! DOM changes considertion No Yes Yes Yes Custom Events Yes Yes Yes Yes Readability Good Good V. Good V. Good Cross-Browser Yes Yes Yes Yes Revert Unbind() Die() Undelegate() Off() Cancel Event Propagation Yes No Yes Yes Shortcuts Yes No No No Meaning of Labels - Min Version : Minimum JQuery version that supports this event binder - Recommended : Recommendation by JQuery site and other prominent community members - Dom Change Consideration : Does this event binder respects elements  dynamically added later (More on this below) - Custom Events : Does it allows to trigger custom events (other than standard ones like click etc.) - Readibility : How easy is it to read and understand what's script doing (bit subjective) - Cross Browser : Is it cross browser compatible? - Revert : Corresponding method to undo event binding - Cancel Event Propagation : Is it possible to cancel event b

PHP include statement

Sometimes we need to re-use same code in different PHP files such as Header file . We use same header file in different page. For that reason we need to write same code in different page. It is time consuming and not good way of writing PHP code. To solve this problem we use PHP include() statement. PHP include() statement Structure Now the question is how we use PHP include() statement in our code. We use include syntax to add same type of code. Suppose that, we want to add header.php file in register.php file. We write include("header.php") in the register.php file. So the structure of include() statement is                         include("file name or file path")                  include ("header.php")       PHP include statement example Think that we have a file name title.php that show the title in header.php file. So we write the title.php file. <?php echo "PHP Tutorials"; ?>  And our header.php file is <html> <title>

Step by step blog creation tutorials using PHP & MySQL: Part-3

Image
E-R Diagram Design: Hello everyone, today I want to start our tutorials with some important discussion. A visitor asked me that, I am learning PHP but I don’t completed all PHP essential tutorials. Am I capable of reading PHP blog tutorials. I say that it is very tough to understand some concepts before learning PHP basic concept. So I say that at first try to learn PHP basic tutorial then try our blog creation tutorials.     So now turn our main PHP blog creation tutorials. Today I show you how to draw the entity relationship diagram for PHP blog. So at first you need to know what is E-R diagram. Entity Relationship diagram is a diagram that show you the relation between the entity. E-R diagram helps us to design our blog database. It is a part of database design. Think that a user make a comment in our blog. User and Comments is two entity of our PHP blog. So that, there is a relation between user and comments entity because user make comments. So the diagram is  We use a arrow si