Archive

Posts Tagged ‘PHP’

PHP Remove Duplicate Array Values From Multidimentional Array

August 27, 2012 Leave a comment

    PHP Remove Duplicate Array Values From Multidimentional Array

$inputArray =

Array
(
[0] => Array
(
[0] => 1
[1] => 3
[2] => 6
)

[1] => Array
(
[0] => 2
[1] => 5
)

[2] => Array
(
[0] => 1
[1] => 3
[2] => 6
)

[3] => Array
(
[0] => 2
[1] => 5
)

[4] => Array
(
[0] => 1
[1] => 3
[2] => 6
)

)

$input = array_map(“unserialize”, array_unique(array_map(“serialize”, $inputArray)));

/******** Output *************/

Array
(
[0] => Array
(
[0] => 1
[1] => 3
[2] => 6
)

[1] => Array
(
[0] => 2
[1] => 5
)

)

/*********************** end make unique array *********************/

Advertisements
Categories: PHP Tags: ,

Time Compare Between Times

$shiftInTime = strtotime($shiftInTime);
$punchInTime = strtotime($punchInTime);
if($shiftInTime <= $punchInTime)
{ Echo $present = ‘present’;}
Else
{ Echo “Absence”;
}

Categories: Date Time, PHP Tags: ,

Add Extra Minutes into input time

$punchInTime = ’09:00:00′;
$graceTime = ’30’;
$mytime = ($punchInTime = date(“H:i:s”, strtotime( “$punchInTime + $graceTime mins”)));
Echo $mytime;

Categories: Date Time, PHP Tags:

Extract date from Strtotime Format

$d = ‘2011-05-23’;
echo $strToTimeToOrginalDate = date(‘Y-m-d’, strtotime($d));

Categories: Date Time, PHP Tags:

Time Difference between times ( start time and end time )

// an START time value
$start = ’09:00′;
// an END time value
$end = ’10:30′;

// what is the time difference between $end and $start?
if( $diff=@get_time_difference($start, $end) )
{
echo “Hours: ” .
sprintf( ‘%02d:%02d’, $diff[‘hours’], $diff[‘minutes’] );
}
else
{
echo “Hours: Error”;
}

//Call function for time diff

function get_time_difference( $start, $end )
{ $uts[‘start’] = strtotime( $start );
$uts[‘end’] = strtotime( $end );
if( $uts[‘start’]!==-1 && $uts[‘end’]!==-1 )
{
if( $uts[‘end’] >= $uts[‘start’] )
{
$diff = $uts[‘end’] – $uts[‘start’];
if( $days=intval((floor($diff/86400))) )
$diff = $diff % 86400;
if( $hours=intval((floor($diff/3600))) )
$diff = $diff % 3600;
if( $minutes=intval((floor($diff/60))) )
$diff = $diff % 60;
$diff = intval( $diff );
return( array(‘days’=>$days, ‘hours’=>$hours, ‘minutes’=>$minutes, ‘seconds’=>$diff) );
}
else
{
trigger_error( “Ending date/time is earlier than the start date/time”, E_USER_WARNING );
}
}
else
{
trigger_error( “Invalid date/time data detected”, E_USER_WARNING );
}
return( false );
}

Categories: Date Time, PHP Tags: ,

Get Last week dates given days name

$tuesday = strtotime(‘last Tuesday’);
echo date(“Y-m-d”, $tuesday) ;

Categories: Date Time, PHP Tags:

Get First day of input dates and last day of input date

$mydate = ‘2011-02-04’;

//Get First Day date from given date
echo date(“Y-m-1”, strtotime($mydate) ) ;

//Get Last Day date from given date
echo date(“Y-m-t”, strtotime($mydate) ) ;

Categories: Date Time, PHP Tags: ,