Tutorial by Examples

A string in PHP is a series of single-byte characters (i.e. there is no native Unicode support) that can be specified in four ways: Single Quoted Displays things almost completely "as is". Variables and most escape sequences will not be interpreted. The exception is that to display a lit...
Determine whether an array is empty or return its size var exampleArray = [1,2,3,4,5] exampleArray.isEmpty //false exampleArray.count //5 Reverse an Array Note: The result is not performed on the array the method is called on and must be put into its own variable. exampleArray = exampleArray...
There are multiple ways to append values onto an array var exampleArray = [1,2,3,4,5] exampleArray.append(6) //exampleArray = [1, 2, 3, 4, 5, 6] var sixOnwards = [7,8,9,10] exampleArray += sixOnwards //exampleArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and remove values from an array exampleAr...
Since PHP 5.0, PDO has been available as a database access layer. It is database agnostic, and so the following connection example code should work for any of its supported databases simply by changing the DSN. // First, create the database handle //Using MySQL (connection via local socket): $d...
The basic syntax of SELECT with WHERE clause is: SELECT column1, column2, columnN FROM table_name WHERE [condition] The [condition] can be any SQL expression, specified using comparison or logical operators like >, <, =, <>, >=, <=, LIKE, NOT, IN, BETWEEN etc. The following ...
SELECT PhoneNumber, Email, PreferredContact FROM Customers This statement will return the columns PhoneNumber, Email, and PreferredContact from all rows of the Customers table. Also the columns will be returned in the sequence in which they appear in the SELECT clause. The re...
Definition: In computing, an event is an action or occurrence recognized by software that may be handled by the software. Computer events can be generated or triggered by the system, by the user or in other ways. Definition Source HTML events are "things" that happen to HTML ele...
The removeEventListener() method removes event handlers that have been attached with the addEventListener() method: element.removeEventListener("mousemove", myFunction); Everything (eventname, function, and options) in the removeEventListener must match the one set when adding the even...
One of the most commonly used events is waiting for the document to have loaded, including both script files and images. The load event on document is used for this. document.addEventListener('load', function() { console.log("Everything has now loaded!"); }); Sometimes you try to ...
A hash in Ruby is an object that implements a hash table, mapping keys to values. Ruby supports a specific literal syntax for defining hashes using {}: my_hash = {} # an empty hash grades = { 'Mark' => 15, 'Jimmy' => 10, 'Jack' => 10 } A hash can also be created using the standard new...
Individual values of a hash are read and written using the [] and []= methods: my_hash = { length: 4, width: 5 } my_hash[:length] #=> => 4 my_hash[:height] = 9 my_hash #=> {:length => 4, :width => 5, :height => 9 } By default, accessing a key which has not been added t...
By default, attempting to lookup the value for a key which does not exist will return nil. You can optionally specify some other value to return (or an action to take) when the hash is accessed with a non-existent key. Although this is referred to as "the default value", it need not be a s...
The differences between null and undefined null and undefined share abstract equality == but not strict equality ===, null == undefined // true null === undefined // false They represent slightly different things: undefined represents the absence of a value, such as before an identifier/...
The json module contains functions for both reading and writing to and from unicode strings, and reading and writing to and from files. These are differentiated by a trailing s in the function name. In these examples we use a StringIO object, but the same functions would apply for any file-like obje...
For any iterable (for eg. a string, list, etc), Python allows you to slice and return a substring or sublist of its data. Format for slicing: iterable_name[start:stop:step] where, start is the first index of the slice. Defaults to 0 (the index of the first element) stop one past the last in...
A quick way to make a copy of an array (as opposed to assigning a variable with another reference to the original array) is: arr[:] Let's examine the syntax. [:] means that start, end, and slice are all omitted. They default to 0, len(arr), and 1, respectively, meaning that subarray that we are ...
You can use slices to very easily reverse a str, list, or tuple (or basically any collection object that implements slicing with the step parameter). Here is an example of reversing a string, although this applies equally to the other types listed above: s = 'reverse me!' s[::-1] # '!em esrever...
When the commits on two branches don't conflict, Git can automatically merge them: ~/Stack Overflow(branch:master) » git merge another_branch Auto-merging file_a Merge made by the 'recursive' strategy. file_a | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
A generator object supports the iterator protocol. That is, it provides a next() method (__next__() in Python 3.x), which is used to step through its execution, and its __iter__ method returns itself. This means that a generator can be used in any language construct which supports generic iterable o...
The next() built-in is a convenient wrapper which can be used to receive a value from any iterator (including a generator iterator) and to provide a default value in case the iterator is exhausted. def nums(): yield 1 yield 2 yield 3 generator = nums() next(generator, None) # 1 ...

Page 38 of 1336