chmod is short for change mode. It is the linux command used to change file permissions. The basic format of the command is like this: chmod options permissions filename There are a number of options, but one of the more
Changing the color of the first word
The question/problem is: Write a PHP script, which changes the color of the first character of a word. This challenge tests your knowledge of preg_replace, and regular expressions. $text = ‘PHP Tutorial’; $text = preg_replace(‘/(\b[a-z])/i’,'<span style=”color: red;”>\1′,$text); echo $text; ?>
SQL sub query challenge
Goal: Write a query which will get the first and last name from the customer table, and the total amount of all that customer’s orders. SELECT first,last FROM customers C This will get all the customers.Next we need to write
Reference challenge
This one tests your knowledge of how reference variables work: $a = ‘P’; $b = &$a; $b = “PH$b”; What will $a and $b be after these three lines of code run? First, $a is set to ‘P’. Then, $b
Base class or Interface?
When making the decision to use a base class or interface, it may help to think of the implementation. If all the implementations are going to be similar, then you might want to group them under a base class. But
preg_match problem
Given: $a = “4|6|3|5|x|2|”; Write code that will output: “2|3|4|5|6” It could be done the long way round, by turning the string into an array, looping over each element, testing each item to see if it’s a number, and placing
MySql Limit
SELECT c.first_name,c.last_name, o.order_total FROM customers c LEFT OUTER JOIN orders o ON c.id = o.cust_id WHERE o.order_total > 100.0 I was once asked to write a query similar to this. The goal was to select all customers who had placed
Array Sorting
I came across this problem recently: How would you sort an array of strings to their natural case-insensitive order, while maintaining their original index association? array( ‘0’ => ‘z1’, ‘1’ => ‘Z10’, ‘2’ => ‘z12’, ‘3’ => ‘Z2’, ‘4’ =>
How to enable PHP error reporting
ini_set(‘display_errors, 1); error_reporting(E_ALL); The ini_set function sets a configuration option for the duration of the script execution. When the script is done, the value returns to whatever it was set to originally in the ini file. The error_reporting function
Coerced in two different ways
$x = NULL; if (‘0xFF’ == 255) { $x = (int)’0xFF’; } This problem tests your knowledge of how type juggling, or coercion works. When a string and a number are compared with the equality operator, the string is coerced
and, it’s not what you expected
$x = true and false; var_dump($x); This one is interesting. In PHP, you can use && or and to do a logical comparison. However, due to the Operator Precedence rules, and actually has lower precedence than =, where && has higher!
Testing your knowledge of array_merge
$arr = array(); $arr[‘val1’] = array(1, 2); $arr[‘val2’] = 3; $arr[‘val3’] = array(4, 5); $arr2 = array(); $arr2 = array_merge($arr2, $arr[‘val1’]); var_dump($arr2); $arr2 = array_merge($arr2, $arr[‘val2’]); var_dump($arr2); $arr2 = array_merge($arr2, $arr[‘val3′]); var_dump($arr2); There’s a problem with this code. It lies
Watch out for that Octal!
var_dump(0123 == 123); var_dump(‘0123’ == 123); var_dump(‘0123’ === 123); At first glance one might think that the leading zero on line one is simply of no value. But one would be wrong… In PHP, a leading zero in a number
strpos gotcha!
$string1 = ‘php is fun!’; $string2 = ‘php’; if (strpos($string1,$string2)) { echo “\”” . $string1 . “\” contains \”” . $string2 . “\””; } else { echo “\”” . $string1 . “\” does not contain \”” . $string2 . “\””;
Post-Fix Increment Problem with Solution
Today I saw an interesting problem. At first glance I wasn’t sure what I was looking at. It took me a moment to parse it. Here is my own version of the problem: $x = 3; echo $x; echo “<br
Imperative vs Declarative (Why OOP is good)
Imperative Programming focuses on how a program operates. Declarative programing focuses on what the program should accomplish without specifying how it will accomplish it. In a way, the Abstraction of Object Oriented Programming can be viewed as a more Declarative
What is Closure in JavaScript?
Closure in JavaScript is when a function is able to remember and access it’s lexical scope even when it is executed outside of it’s lexical scope. Put another way, it’s a function which can access it’s lexical scope after the
ACID
A.C.I.D. Atomicity Consistency Isolation Durability Atomicity in a database system means that a sequence of events within a transaction must all occur or nothing occurs. Because of this, the transaction cannot be observed by an outside process as “in progress”.
A PIE
There are 4 basic features that an object oriented language has. Here is an easy way to remember them: “A Pie” Abstraction Polymorphism Inheritance Encapsulation Abstraction means that only necessary information is exposed outside the class, and the details of
Making progress in Laravel
I’m making good progress in learning Laravel. I just wrote a service provider, and then created a Facade for it. The concepts are coming together nicely. Here are a few of the pages I used to help figure this out: https://laravel.com/docs/5.2/providers#registering-providers