Useful Functions

Keyword Description Example OUTPUT / Others
filemtime filemtime — Gets file modification time. This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed. <?php // outputs e.g. somefile.txt was last modified: December 29 2002 22:16:23.
$filename = 'somefile.txt';
if (file_exists($filename)) {
echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
} ?>
php -f file.php   That will run and output the PHP file to the terminal. If you've got a ton of HTML in the php file or it relies on various $_SERVER variables, this just isn't going to work.  
tailf latlogprocess.txt   It shows the output in terminal as new lines added to text file  
Error Reporting in PHP error_reporting(E_ERROR | E_PARSE);   Normally, in order to maintain state in web application, one uses cookies.
Time zone setting in PHP date_default_timezone_set('Asia/Kolkata');    
show databases List all databases    
mysql_affected_rows mysql_affected_rows — Get number of affected rows in previous MySQL operation mysql_affected_rows();  
PDOStatement::rowCount PDOStatement::rowCount — Returns the number of rows affected by the last SQL statement PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.  
strpos strpos — Find the position of the first occurrence of a substring in a string $mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
array_walk array_walk — Apply a user function to every member of an array <?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");

function test_alter(&$item1, $key, $prefix){

$item1 = "$prefix: $item1";

function test_print($item2, $key){
echo "$key. $item2<br />n";

echo "Before …:n";
array_walk($fruits, 'test_print');

array_walk($fruits, 'test_alter', 'fruit');
echo "… and after:n";

array_walk($fruits, 'test_print');?>

array_search array_search — Searches the array for a given value and returns the corresponding key if successful <?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');

$key = array_search('green', $array); // $key = 2;

$key = array_search('red', $array); // $key = 1;?>

array_column array_column — Return the values from a single column in the input array <?php
// Array representing a possible record set returned from a database
$records = array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',

$first_names = array_column($records, 'first_name');

[0] => John
[1] => Sally
[2] => Jane
[3] => Peter
get_included_files get_included_files — Returns an array with the names of included or required files

// This file is abc.php

include 'test1.php';

include_once 'test2.php';
require 'test3.php';
require_once 'test4.php';

$included_files = get_included_files();

foreach ($included_files as $filename) {
echo "$filenamen";

reset reset — Set the internal pointer of an array to its first element <?php
$array = array('step one', 'step two', 'step three', 'step four');
// by default, the pointer is on the first element
echo current($array) . "<br />n"; // "step one"
// skip two steps
echo current($array) . "<br />n"; // "step three"
// reset pointer, start again on step one
echo current($array) . "<br />n"; // "step one"
key Fetch a key from an array. key() returns the index element of the current array position <?php
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');

// this cycle echoes all associative array
// key where value equals "apple"
while ($fruit_name = current($array)) {
if ($fruit_name == 'apple') {
echo key($array).'<br />';

fruit1<br />
fruit4<br />
fruit5<br />
array_shift Shift an element off the beginning of array <?php
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_shift($stack);
Array (
[0] => banana
[1] => apple
[2] => raspberry
) and orange will be assigned to $fruit.
console.log What is the use of console.log?




Please explain how to use it in JavaScript, with a code example.

It's not a jQuery feature but a feature of Firebug (or some other tool). It's used for debugging. You can for instance log something to the console when something happens. For instance:

$( '#someButton' ).click ( function () {

console.log ( '#someButton was clicked' );
// do something
} );
You'd then see #someButton was clicked in Firebug’s “Console” tab (or another tool’s console — e.g. Chrome’s Web Inspector) when you would click the button.

edit: as Baptiste Pernet showed in his answer you could first check if console is even avaliable. This is usefull as you don't have to remove your debugging code when you deploy to production:

if ( window.console && window.console.log ) {
// console is available


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>