Wednesday, July 18, 2012

Compare two array has equal values


for eg;
$restids = array("apple","mango");
$asvals = array("apple","mango");

You can't get the results for equal array check with array_diff function if the second array dynamically changes

You can do on thing for this

if(count(array_diff($restids,$asvals)) == 0 && count(array_diff($asvals,$restids)) == 0){
    return true;
}

This condition will get you the if two array has equal values or not.

Wednesday, July 4, 2012

Use of in condition & between condition in db_select in drupal7


$res = array(‘test1’,’test2’);
$sql_query = db_select(testtable', 's');
$sql_query->fields('s', array('filename', 'filetype', 'createdon'));
$sql_query->condition('s.filetype',$res,'IN');
$datearray = array(‘2011-02-02’,date('Y-m-d'));
$sql_query->condition('s.createdon',$datearray,'BETWEEN');
$sql_query = $sql_query->limit(5)->execute();