Writing to Java Script Console PRO

We can easily track our code in Java Script by writing text messages to the Java Script console. The following code sample shows how to do it. <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”> <html> <head> <title></title> <script type=”text/javascript”> var sum = 0; for(i=1; i<=10; i++) { sum+=i; console.log(“i=”+i); console.log(“sum=”+sum); } document.write(“sum=”+sum); </script> </head> […]

Simple Trait in PHP PRO

Defining a trait is very similar to defining a class. Instead of using the keyword class we use the keyword trait. The purpose of traits is to group functionality in a fine grained and consistent way. It is not possible to instantiate a trait. The trait servers as an additional capability that provides us with additional capabilities when […]

Arrays Short Syntax in PHP 5.4 PRO

As of PHP 5.4 we can create new arrays in a simple way. Simpler than ever. The following code sample shows that. <?php $vec_a = [4,6,2,7]; $vec_b = [‘a’=>’australia’,’b’=>’belgium’,’c’=>’canada’]; foreach($vec_a as $k=>$v) { echo ” “.$k.”=>”.$v; } foreach($vec_b as $k=>$v) { echo ” “.$k.”=>”.$v; } ?> The following video clip shows the execution of this […]

Array Dereference in PHP 5.4 PRO

As of PHP 5.4 we can develop a function that returns an array and treat the call to that function as an array we want to access its elements. <?php function doSomething() { $vec = [23,53,75,64]; return $vec; } echo doSomething()[0]; ?> The following video clip shows the execution of this code sample and explains […]

The PHP 5.2 filter_var Function PRO

PHP 5.2 adds the filter_var function. It is an important function that assists with validating the user input. <?php $email_address_dirty = “haim.michael@gmail.com”; if(filter_var($email_address_dirty,FILTER_VALIDATE_EMAIL)) { $email_address_clean = $email_address_dirty; } echo $email_address_clean; ?> The following video clip shows the execution of this code sample and explains it.

PHP 5.4 Short Tags PRO

As of PHP 5.4, the support for short tags exists by default. There is no need to introduce changes into php.ini in order to use the PHP short tags. <? $numA = 24; $numB = 4; ?> <h1><?=($numA+$numB)?></h1> The following video clip shows the execution of this code sample and explains it.

PHP 5.4 Access Members on Instantiation PRO

PHP 5.4 allows us to access class members on the instantiation. We will use this special capability in those rare cases in which the only reason for creating the object is in order to allow us to access one of the class members. <? class Utils { function calc($numA,$numB) { return $numA+$numB; } } $temp […]

Skip to content Update cookies preferences