Tutorial by Examples: e

PHP provides an alternative syntax for some control structures: if, while, for, foreach, and switch. When compared to the normal syntax, the difference is, that the opening brace is replaced by a colon (:) and the closing brace is replaced by endif;, endwhile;, endfor;, endforeach;, or endswitch;, ...
while loop iterates through a block of code as long as a specified condition is true. $i = 1; while ($i < 10) { echo $i; $i++; } Output: 123456789 For detailed information, see the Loops topic.
do-while loop first executes a block of code once, in every case, then iterates through that block of code as long as a specified condition is true. $i = 0; do { $i++; echo $i; } while ($i < 10); Output: `12345678910` For detailed information, see the Loops topic.
declare is used to set an execution directive for a block of code. The following directives are recognized: ticks encoding strict_types For instance, set ticks to 1: declare(ticks=1); To enable strict type mode, the declare statement is used with the strict_types declaration: declare(s...
The if statement in the example above allows to execute a code fragment, when the condition is met. When you want to execute a code fragment, when the condition is not met you extend the if with an else. if ($a > $b) { echo "a is greater than b"; } else { echo "a is NOT gre...
require require is similar to include, except that it will produce a fatal E_COMPILE_ERROR level error on failure. When the require fails, it will halt the script. When the include fails, it will not halt the script and only emit E_WARNING. require 'file.php'; PHP Manual - Control Structures - ...
The return statement returns the program control to the calling function. When return is called from within a function, the execution of the current function will end. function returnEndsFunctions() { echo 'This is executed'; return; echo 'This is not executed.'; } When you run re...
foreach is a construct, which enables you to iterate over arrays and objects easily. $array = [1, 2, 3]; foreach ($array as $value) { echo $value; } Outputs: 123. To use foreach loop with an object, it has to implement Iterator interface. When you iterate over associative arrays: $arra...
elseif elseif combines if and else. The if statement is extended to execute a different statement in case the original if expression is not met. But, the alternative expression is only executed, when the elseif conditional expression is met. The following code displays either "a is bigger tha...
In this example we show how to generate a simple sine wave, and output it on the user's speakers/headphones. let audioContext = new (window.AudioContext || window.webkitAudioContext)(); let sourceNode = audioContext.createOscillator(); sourceNode.type = 'sine'; sourceNode.frequency.value = 261...
Effects can be applied to audio by chaining nodes between the source and the destination node. In this example we use a gain node to mute the source, and only let sound through at specific times. This allows us to create morse code. function morse(gainNode, pattern) { let silenceTimeout = 300; ...
Assuming we want to modify bit n of an integer primitive, i (byte, short, char, int, or long): (i & 1 << n) != 0 // checks bit 'n' i |= 1 << n; // sets bit 'n' to 1 i &= ~(1 << n); // sets bit 'n' to 0 i ^= 1 << n; // toggles the value of bit 'n' Us...
You must be very careful when providing a forwarding reference overload as it may match too well: struct A { A() = default; // #1 A(A const& ) = default; // #2 template <class T> A(T&& ); // #3 }; The intent here was that A is c...
Pointers can also be used to point at functions. Let's take a basic function: int my_function(int a, int b) { return 2 * a + 3 * b; } Now, let's define a pointer of that function's type: int (*my_pointer)(int, int); To create one, just use this template: return_type_of_func (*my_fun...
In Index page change the following: error_reporting(E_ALL | E_STRICT); to error_reporting(E_ALL); Set $_SERVER['MAGE_IS_DEVELOPER_MODE'] = true and uncomment this line (remove the #) #ini_set('display_errors', 1); You can also Set Dev Mode using SetEnv in your .htaccess file To make th...
Creating and returning an image object by loading the image data from the file at the specified path. Example: UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[cellCountry objectForKey:@"Country_Flag"] ofType:nil]]; Using Array: Example NSM...
Template <div id="example"> a={{ a }}, b={{ b }} </div> JavaScript var vm = new Vue({ el: '#example', data: { a: 1 }, computed: { // a computed getter b: function () { // `this` points to the vm instance return this.a + 1 }...
The general format for namespaces is: <Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]. Examples include: Fabrikam.Math Litware.Security Prefixing namespace names with a company name prevents namespaces from different companies from having the sa...
Objective-C //set off-image mySwitch.offImage = [UIImage imageNamed:@"off_image"]; [mySwitch setOffImage:[UIImage imageNamed:@"off_image"]]; //set on-image mySwitch.onImage = [UIImage imageNamed:@"on_image"]; [mySwitch setOnImage:[UIImage imageNamed:@"on_im...
# Extract strings with a specific regex df= df['col_name'].str.extract[r'[Aa-Zz]'] # Replace strings within a regex df['col_name'].str.replace('Replace this', 'With this') For information on how to match strings using regex, see Getting started with Regular Expressions.

Page 259 of 1191