PHP: Find every combination of an Array

$words = array(‘red’, ‘blue’, ‘green’);
$num = count($words);

//The total number of possible combinations
$total = pow(2, $num);

//Loop through each possible combination
for ($i = 0; $i < $total; $i++) {
//For each combination check if each bit is set
for ($j = 0; $j < $num; $j++) {
//Is bit $j set in $i?
if (pow(2, $j) & $i) echo $words[$j] . ‘ ‘;
}
echo ‘<br />’;
}

 

 

OUTPUT:

 

red
blue
red blue
green
red green
blue green
red blue green

 

 

PHP random string generator

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}


Output the random string with the call below:

// Echo the random string.
// Optionally, you can give it a desired string length.
echo generateRandomString();

How to install Zend Framework 2 in ubuntu

http://www.flipkart.com/affiliate/displayWidget?affrid=WRID-142382037023472768

1)Getting started: A skeleton application

Luckily the people from Zend provide a Skeleton application as starting point. Therefore, you do not need to create the project setup from scratch.

Create your application’s base folder and run the following commands.

 cd /my-project/dir
 git clone git://github.com/zendframework/ZendSkeletonApplication.git
 cd ZendSkeletonApplication
 php composer.phar self-update
 php composer.phar install


 Thats all,
Run http://localhost/my-project-name/public

Example

Run http://localhost/zf2-tutorial/public

2)Adding a Virtual Host

You now need to create an Apache virtual host for the application and edit your hosts file so that http://zf2-tutorial.localhost will serve index.php from the zf2-tutorial/public directory.

Setting up the virtual host is usually done within httpd.conf or extra/httpd-vhosts.conf. If you are using httpd-vhosts.conf, ensure that this file is included by your main httpd.conf file. Some Linux distributions (ex: Ubuntu) package Apache so that configuration files are stored in /etc/apache2 and create one file per virtual host inside folder /etc/apache2/sites-enabled. In this case, you would place the virtual host block below into the file /etc/apache2/sites-enabled/zf2-tutorial.

Ensure that NameVirtualHost is defined and set to “*:80” or similar, and then define a virtual host along these lines:

 

 <VirtualHost *:80>
     ServerName zf2-tutorial.localhost
     DocumentRoot /path/to/zf2-tutorial/public
     SetEnv APPLICATION_ENV "development"
     <Directory /path/to/zf2-tutorial/public>
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all
     </Directory>
 </VirtualHost>

 

Since we are building an application we will have 3 environments (development, staging, and production).

Development

This is our working copy. This version of the code contains the latest version and all the experimental features. Developers directly interact with this copy and continuously change, modify and test the latest integration and features.

Staging

The staging environment contains the next release candidate and is usually one version ahead of the production version. In this version final tests are performed and almost no new features are introduced. If you are working with a team, this environment is where your code and your project team code are combined and validated for production.

Production

This is the stable released version of the software available to the end-users. This version does not change until the next iteration of the software is proven to be stable in the staging environment and ready to be released. Production environment is the actual environment in which your system will run after deployment.

 

 

Make sure that you update your /etc/hosts or c:\windows\system32\drivers\etc\hosts file so that zf2-tutorial.localhost is mapped to 127.0.0.1. The website can then be accessed using http://zf2-tutorial.localhost.

127.0.0.1 zf2-tutorial.localhost localhost

Restart Apache.

user-guide.skeleton-application.hello-world

If you get this Page . Your app is working fine.