Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Wednesday, April 13, 2016

PHP for Beginners

An excellent resource for PHP tutorials can be located here! There are many explanations on different concepts and tutorials on how to code PHP.

I hope you find it useful! 


Loops

Loops are a very powerful tool in PHP. Today, I will explain the different types briefly as an overview. There are some basic loops in PHP that are very similar to the three basic loops in Java in addition to a new one:

  • while
  • do...while
  • for
  • foreach
The first three loops perform the same as they do in Java, so it makes it easier for beginner developers to switch from one language to the other. Because of the familiarity, I will be brief in my explanations for these loops.

The while loop is for when the developer wants to perform an action if the condition is true. If not, then the code will be skipped over.

A do...while loop is for when the developer wants to perform an action at least once while the condition is true. 

A for loop is usually for when the developer has a set amount of times that the section of code should be looped. This loop is more efficient than the others because it can initialize, compare, and modify a variable all in one line.

A foreach loop is the new addition that is not in Java! This loop takes each element in an array, sets it to a variable, and performs an action on it. After that, the pointer will move to the next element and continue from there. To help explain this concept further, watch the video below:




Source: http://www.tutorialspoint.com/php/php_loop_types.htm

Monday, April 11, 2016

Form Input Types

There are different input types that can be used when creating forms with input fields. Today I will only discuss a select few because not all are supported by every browser.

The different types are:
  • text boxes
  • text areas
  • checkboxes
  • radio buttons
  • submit button


The text boxes are for input types that handle text in only one line. The user can input letters, numbers, and other characters in this field.

The text areas are for input types that handle text in multiple lines. This type is not that different from a text box; the small differences being the multiple line and word wrap ability.

Checkboxes are for selections of more than one. The selections usually have a small, square box that the user can select, and some type of marking will show up as the user clicks on it. The developer can choose to have boxes already checked.

Radio buttons are for selections of only one. These selections usually have small, round circles that the user can select, and the circle will be filled as the user chooses it. The developer can also choose to have a button already filled in. An example of radio buttons in use can be seen with my poll on the right sidebar.

The submit button is for submitting the form. The developer can change the appearance of the button with a picture, or the developer can change the text that the button displays.

This was only a brief overview of these concepts, but I hoped it helped you in some way.


Source: http://www.w3schools.com/html/html_form_input_types.asp

Saturday, April 2, 2016

Understanding PHP Arrays

Arrays in PHP are a very useful tool to use when a developer wants to put several valuables in a list or table format. This makes it easy to categorize and retrieve values from one variable. There are three types of arrays in PHP: indexed, associative, and multidimensional.
  • An indexed array is where the indexes of the array are integers, starting with 0.
    An example of assignment:
    $example_array[0] = 1;
  • An associative array is where the indexes of the array are alphanumeric, which means that the developer can name the index in either letters, numbers, or both.
    An example of assignment:
    $example_array['George'] = 45;
  • A multidimensional array is where an array lies within another array. The developer can nest arrays so that there can be multiple dimensions, like a 3 x 4 table. 
The array variable also comes with a multitude of preset functions such as count() and array(). The array() function is particularly useful since it saves the time of writing out the name of the array repetitively when assigning multiple values. With this function, the developer can insert large amounts of values at once in one command line:
  • $example_array = array("Beth", "Andrew", "Grace");
Through using a for or foreach loop, it is easy to retrieve values from one variable instead of trying to retrieve a value from a large amount of separate variables. There can be many ways to write out these loops since there are many purposes that it may serve such as sorting, retrieving, print out, and much more.

Arrays are excellent tools to use when handling large amounts of data, and they come with a variety of functions as well. Here is a helpful video:


Source: http://www.w3schools.com/php/php_arrays.asphttp://www.w3schools.com/php/php_arrays_multi.asp