PHP

Use in_array() for compare string condition

Tags: 

PHP

See this code

if($string == 'word1' || $string == 'word2')
{
  // Do Something
} elseif($string == 'word3' || $string == 'word4' || $string == 'word5' || $string == 'word6' || $string == 'word7') {
  // Do Something
}

First if still ok to use but in next elseif is too long! So I tried to find better way to compare many string and in_array() function is the answer.

if(in_array($string, array('word1', 'word2')))
{
  // Do Something
} elseif(in_array($string, array('word3', 'word4', 'word5', 'word6', 'word7'))) {
  // Do Something
}

PHP Short If-Else

Tags: 

PHP

From this code

if($login)
  echo 'Welcome'.$username;
else
  echo 'Welcome Guest';

We can use short if-else for compact and effective by below code

echo 'Welcome '.($login ? $username : 'Guest');

How to choosing PHP module for Apache

Tags: 

Apache

Since I use my old 2 years hosting server. It's time to upgrade to new server with high performance to support more customers. So I have to research about installation and tuning DirectAdmin. One factor that is very important is Apache. There are many differ performance between system with tuning and without.

Factors that we have to think about choosing PHP module for Apache are performance and security. Some modules come with great performance but trade off with security while some modules are opposite.

While googling, I found some interesting data Benchmark Comparison on Serving Simple PHP: LiteSpeed vs Apache vs Nginx so I choose only mod_php, mod_fastcgi, mod_fcgid and suPHP to compare and analysis in this article.

Install Apache + MySQL + PHP with one command on Linux with XAMPP

Tags: 

Amateur web developers always have problem with installation of Apache + MySQL + PHP to test their code including many administrators that want to install LAMPP Server (LAMPP stands for Linux + Apache + MySQL + PHP + Perl) for doing simple web server (with less security without strict configuration). So there are software that include all LAMPP with only one installation. XAMPP is the most popular one.

Subscribe to RSS - PHP