Some PHP developer interview algorithms you must now

FizzBuzz:

http://3v4l.org/mIBmo

<?php

for ($i = 0; $i <= 30; $i++) {
    if ($i % 3 == 0 && $i % 5 == 0) {
        echo "$i: FizzBuzz; ";
    } elseif ($i % 3 == 0) {
        echo "$i: Fizz; ";
    } elseif ($i % 5 == 0) {
        echo "$i: Buzz; ";
    }
}

Swap 2 vars values without using a third one:

Numbers and strings with XOR:

http://3v4l.org/dsBvh

<?php

$a = 3;
$b = 5;

$a = $a+$b;
$b = $a-$b;
$a = $a-$b;

echo "a = $a; b = $b";

and:

http://3v4l.org/aqWcl

<?php

for ($i = 0; $i <= 30; $i++) {
    if ($i % 3 == 0 && $i % 5 == 0) {
        echo "$i: FizzBuzz; ";
    } elseif ($i % 3 == 0) {
        echo "$i: Fizz; ";
    } elseif ($i % 5 == 0) {
        echo "$i: Buzz; ";
    }
}

Swap 2 strings without using XOR:

http://3v4l.org/FDFDF

<?php
$a = 'texta';
$b = 'textb';
$a = $a . $b; //textatextb
$b = substr($a, 0, strlen($a) - strlen($b)); //texta
$a = substr($a, strlen($b)); //textb
echo "a = $a; b = $b";

Your first app: node.js by Jim Schubert

I started reading the book "Your first app: node.js" by Jim Schubert.It has a good ...

Learn more

About Iliyan Trifonov

Web Developer, Blogger
Bookmark the permalink.