Category Archives: Coding

Unset an array item in a foreach loop

Trying to remove an item from a PHP foreach loop is not a straight forward job, because, PHP works on a copy of that array, so you need to do it like this:

$items = array('a','b','c','d');
foreach ($items as $key => $value) {
    if ($value=='b' || $value=='d') {

this outputs:

array(2) {
  string(1) "a"
  string(1) "c"

How to protect your PHP website against SQL injection

Mysql injection is a method to attack the database by inserting extra sql statements, that when executed could help an attacker do what he wants with the database.

Continue reading How to protect your PHP website against SQL injection

How to make NetBeans auto complete better in PHP ?

NetBeans have good autocomplete, it helps productivity and reduce wasted time, but it can be better by using PHPDoc. NetBeans need to know what data types does the variable contains to be able to auto complete it to give it hints about what the data types of variables or function parameters.

Consider this example:

class class2 {
     * @var string
    public $var = null;
class class1 {
     * @var class2 
    static $some_class = null;
     * @var string 
    static $some_var = null;
     * @param array $in_val
     * @return array
    static function functionName($in_val) {

After you add the PHPDoc values like above, if you try in your code doing something like this:


it will give you a hint that it can be auto completed to:


and when you do:


it will also hint to this:


Pretty powerful, isn’t it?

There is probably more details on PHPDoc than this. but for many, this little addition to autocomplete could make a big change.