How do I sort a multidimensional array in php


Deprecated: Function create_function() is deprecated in /home/ursaftwz/public_html/myscripthub.com/wp-content/plugins/codecolorer/lib/geshi.php on line 4698
1
2
3
4
5
6
7
8
9
10
11
12
13
function aasort (&$array, $key) {
    $sorter=array();
    $ret=array();
    reset($array);
    foreach ($array as $ii => $va) {
        $sorter[$ii]=$va[$key];
    }
    asort($sorter);
    foreach ($sorter as $ii => $va) {
        $ret[$ii]=$array[$ii];
    }
    $array=$ret;
}

Calling of function:
aasort($array,”datetime”);
passed field name and array

Time and Date difference using a PHP function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php function dateTimeDiff($data_ref){

// Get the current date
$current_date = date('Y-m-d H:i:s');

// Extract from $current_date
$current_year = substr($current_date,0,4);
$current_month = substr($current_date,5,2);
$current_day = substr($current_date,8,2);

// Extract from $data_ref
$ref_year = substr($data_ref,0,4);
$ref_month = substr($data_ref,5,2);
$ref_day = substr($data_ref,8,2);

// create a string yyyymmdd 20071021
$tempMaxDate = $current_year . $current_month . $current_day;
$tempDataRef = $ref_year . $ref_month . $ref_day;

$tempDifference = $tempMaxDate-$tempDataRef;

// If the difference is GT 10 days show the date
if($tempDifference >= 10){
echo $data_ref;
} else {

// Extract $current_date H:m:ss
$current_hour = substr($current_date,11,2);
$current_min = substr($current_date,14,2);
$current_seconds = substr($current_date,17,2);

// Extract $data_ref Date H:m:ss
$ref_hour = substr($data_ref,11,2);
$ref_min = substr($data_ref,14,2);
$ref_seconds = substr($data_ref,17,2);

$hDf = $current_hour-$ref_hour;
$mDf = $current_min-$ref_min;
$sDf = $current_seconds-$ref_seconds;

// Show time difference ex: 2 min 54 sec ago.
if($dDf<1){
if($hDf>0){
if($mDf<0){
$mDf = 60 + $mDf;
$hDf = $hDf - 1;
echo $mDf . ' min ago';
} else {
echo $hDf. ' hr ' . $mDf . ' min ago';
}
} else {
if($mDf>0){
echo $mDf . ' min ' . $sDf . ' sec ago';
} else {
echo $sDf . ' sec ago';
}
}
} else {
echo $dDf . ' days ago';
}
?>

and you have to pass the data which it goes made the comparison:
dateTimeDiff($dataRef);

Joomla Jquery not working, why is that?


1
2
<strong>&lt;script type="text/javascript" src="&lt;?php echo $this-&gt;baseurl ?&gt;
/templates/YOUR_TEMPLATE_NAME/PATH_TO_JAVASCRIPT_FOLDER/YOUR_JQUERY.js"&gt;&lt;/script&gt;</strong>
  • YOUR TEMPLATE – Name of you template
  • PATH TO JAVASCRIPT FOLDER – If any folder present then the path of the folder
  • YOUR JQUERY.js – Finally the file name which one you want to include.</div>