Interface in php

Interfaces in php provide a way for defining contracts to which a class adheres; the interface provides method prototypes and constants, and any class that implements the interface must provide implementations for all methods in the interface. Here’s the syntax for an interface definition: interface interfacename{[ function functionname();…]} To declare that a class implements an … Read more

Objects in php

Object-oriented programming (OOP) opens the door to cleaner designs, easier maintenance, and greater code reuse. The proven value of OOP is such that few today would dare to introduce a language that wasn’t object-oriented. PHP supports many useful features of OOP Terminology Every object-oriented language seems to have a different set of terms for the … Read more

php Creating an Object

It’s much easier to create objects and use them than it is to define object classes, to create an object of a given class, use the new keyword: $object = new Class; Assuming that a Person class has been defined, here’s how to create a Person object: $rasmus = new Person; Some classes permit you … Read more

Stacks in php

Although not as common in PHP programs as in other programs, one fairly common data type is the last-in first-out (LIFO) stack. We can create stacks using a pair of PHP functions, array_push() and array_pop(). The array_push() function is identical to an assignment to $array[]. We use array_push() because it accentuates the fact that we’re … Read more

Sets in php

Arrays let you implement the basic operations of set theory: union, intersection, and difference. Each set is represented by an array, and various PHP functions implement the set operations. The values in the set are the values in the array—the keys are not used, but they are generally preserved by the operations. The union of … Read more

php to Calculating the Difference Between Two Arrays

In php The array_diff() function calculates this, returning an array with values from the first array that are not present in the second The array_diff() function identifies values from one array that are not present in others: $diff = array_diff(array1, array2 [, array … ]); For example: $a1 = array(“bill”, “claire”, “ella”, “simon”, “judy”);$a2 = … Read more

Sorting in php

Sorting in php changes the internal order of elements in an array and optionally rewrites the keys to reflect this new order. For example, you might use sorting to arrange a list of scores from biggest to smallest, to alphabetize a list of names or to order a set of users based on how many … Read more

in_array() in php

The in_array() function returns true or false, depending on whether the first argument is an element in the array given as the second argument if (in_array(to_find, array [, strict])) { … } If the optional third argument is true, the types of to_find and the value in the array must match. The default is to … Read more