Tag Archives: php

PHP array tips

Some tips.

1. Remove duplicates in array using array_unique

array array_unique ( array $array [, int $sort_flags = SORT_STRING ] )

2. Remove empty elements use array_filter

array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )

3. value is in the array use in_array

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )

4. key exist in array use array_key_exist

bool array_key_exists ( mixed $key , array $array )


CodeIgniter Quick Reference

Some of useful functions but not all the time use. Will be a quick reference everytime want to use them.

URI segment

$this->uri->segment(3); //will produce: metro


$query = $this->db->query("YOUR QUERY");

if ($query->num_rows() > 0)
        foreach ($query->result() as $row)
                echo $row->title;
                echo $row->name;
                echo $row->body;
$this->db->select('title, content, date');
$this->db->join('comments', 'comments.id = blogs.id');
$this->db->where('name !=', $name);
$this->db->where('title', $title);
$query = $this->db->get('mytable');


Some other bootstrap-related tools to study

Visual Editor

  • bootply.com – online visual bootstrap editor
  • pingendo – free, native (download and install)
  • pinegrow.com – paid (starts at usd49), native + online demo
  • layoutit – free, online editor
  • jetstrap.com – paid

Snippets, tools, themes etc.

  • bootsnipp.com – snippets, form builder
  • startbootstrap.com – theme and templates


  • bootstrap magic – change theme, color and other default look for bootstrap based on your preference
  • codiqa.com – build mobile app easily. nice and easy interface
  • x-editable – library to easily update data in-line without whole form submission
  • bootbundle.com – theme, template, plugins etc. many sites on one.
  • list of more plugins and tools

Sample use of CI query builder for CRUD

Sample insert

$data = array(
        'title' => $title,
        'name' => $name,
        'date' => $date

$this->db->insert('mytable', $data);

Sample update

$this->db->update('mytable', $data, "id = 4"); OR
$this->db->update('mytable', $data, array('id' => $id));

Sample delete

$this->db->delete('mytable', array('id' => $id));

Sample to get data

$where = "name='Joe' AND status='boss' OR status='active'";

More on getting data with CI

CI Query builder reference: CI2, CI3

How to easily create PHP image gallery

This becoming my favorite image gallery now – fotorama.io. So easy to implement with plenty of customization that we can do.

If you don’t believe how easy it is, copy following source code, paste and save as an html file. Then open it and see what will happen.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.js"></script>

<div class="fotorama" data-width="100%" data-ratio="800/600" data-nav="thumbs" data-loop="true" data-allowfullscreen="true">
 <img src="http://s.fotorama.io/1.jpg">
 <img src="http://s.fotorama.io/2.jpg">