Hi Friends,
Can you help me with this,
I would like to get the week number of the "Monday",
Say if we run on first week of november it should give me output as "05" and "10" i.e it says the monday falls on 5th week of october.
If we run on the second week of november it should give me "01"... (8 Replies)
Hi
I want to extract the date on Monday depending upon the user input for that week.
For example if the input date is 20080528 then the output should be 20080526. If the input is 20080525 then it will be 20080519
i am working on IBM AIX
Thanks (2 Replies)
Hi,
I have a requirement where I want to get the date of monday when I am running the script from previous Friday to the following Thursday.
For example: When ever I run the script between 19thFeb2010(Friday) to 25th Feb 2010(Thursday), I should get the date of 22nd Feb 2010 in the format of... (5 Replies)
Hi all,
I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date.
So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Hi All,
I have a requirement which would calculate the Tuesday's date of the current week in yyyymmdd format in unix shell script.
Please help me out how could I do this .
I appreciate your help
Regards,
raj (7 Replies)
Hi ,
Please help me out to write a shell script to obtain the date of first tueday of every month. I am new to shell scripting.
Appreciate your help Thanks. (7 Replies)
Discussion started by: prongs22
7 Replies
LEARN ABOUT PHP
array_udiff
ARRAY_UDIFF(3) 1 ARRAY_UDIFF(3)array_udiff - Computes the difference of arrays by using a callback function for data comparisonSYNOPSIS
array array_udiff (array $array1, array $array2, [array $...], callable $value_compare_func)
DESCRIPTION
Computes the difference of arrays by using a callback function for data comparison. This is unlike array_diff(3) which uses an internal
function for comparing the data.
PARAMETERS
o $array1
- The first array.
o $array2
- The second array.
o $value_compare_func
- The callback comparison function. The comparison function must return an integer less than, equal to, or greater than zero if
the first argument is considered to be respectively less than, equal to, or greater than the second.
int callback (mixed $a, mixed $b)
RETURN VALUES
Returns an array containing all the values of $array1 that are not present in any of the other arguments.
EXAMPLES
Example #1
array_udiff(3) example using stdClass Objects
<?php
// Arrays to compare
$array1 = array(new stdclass, new stdclass,
new stdclass, new stdclass,
);
$array2 = array(
new stdclass, new stdclass,
);
// Set some properties for each object
$array1[0]->width = 11; $array1[0]->height = 3;
$array1[1]->width = 7; $array1[1]->height = 1;
$array1[2]->width = 2; $array1[2]->height = 9;
$array1[3]->width = 5; $array1[3]->height = 7;
$array2[0]->width = 7; $array2[0]->height = 5;
$array2[1]->width = 9; $array2[1]->height = 2;
function compare_by_area($a, $b) {
$areaA = $a->width * $a->height;
$areaB = $b->width * $b->height;
if ($areaA < $areaB) {
return -1;
} elseif ($areaA > $areaB) {
return 1;
} else {
return 0;
}
}
print_r(array_udiff($array1, $array2, 'compare_by_area'));
?>
The above example will output:
Array
(
[0] => stdClass Object
(
[width] => 11
[height] => 3
)
[1] => stdClass Object
(
[width] => 7
[height] => 1
)
)
Example #2
array_udiff(3) example using DateTime Objects
<?php
class MyCalendar {
public $free = array();
public $booked = array();
public function __construct($week = 'now') {
$start = new DateTime($week);
$start->modify('Monday this week midnight');
$end = clone $start;
$end->modify('Friday this week midnight');
$interval = new DateInterval('P1D');
foreach (new DatePeriod($start, $interval, $end) as $freeTime) {
$this->free[] = $freeTime;
}
}
public function bookAppointment(DateTime $date, $note) {
$this->booked[] = array('date' => $date->modify('midnight'), 'note' => $note);
}
public function checkAvailability() {
return array_udiff($this->free, $this->booked, array($this, 'customCompare'));
}
public function customCompare($free, $booked) {
if (is_array($free)) $a = $free['date'];
else $a = $free;
if (is_array($booked)) $b = $booked['date'];
else $b = $booked;
if ($a == $b) {
return 0;
} elseif ($a > $b) {
return 1;
} else {
return -1;
}
}
}
// Create a calendar for weekly appointments
$myCalendar = new MyCalendar;
// Book some appointments for this week
$myCalendar->bookAppointment(new DateTime('Monday this week'), "Cleaning GoogleGuy's apartment.");
$myCalendar->bookAppointment(new DateTime('Wednesday this week'), "Going on a snowboarding trip.");
$myCalendar->bookAppointment(new DateTime('Friday this week'), "Fixing buggy code.");
// Check availability of days by comparing $booked dates against $free dates
echo "I'm available on the following days this week...
";
foreach ($myCalendar->checkAvailability() as $free) {
echo $free->format('l'), "
";
}
echo "
";
echo "I'm busy on the following days this week...
";
foreach ($myCalendar->booked as $booked) {
echo $booked['date']->format('l'), ": ", $booked['note'], "
";
}
?>
The above example will output:
I'm available on the following days this week...
Tuesday
Thursday
I'm busy on the following days this week...
Monday: Cleaning GoogleGuy's apartment.
Wednesday: Going on a snowboarding trip.
Friday: Fixing buggy code.
NOTES
Note
Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by
using array_udiff($array1[0], $array2[0], "data_compare_func");.
SEE ALSO array_diff(3), array_diff_assoc(3), array_diff_uassoc(3), array_udiff_assoc(3), array_udiff_uassoc(3), array_intersect(3), array_inter-
sect_assoc(3), array_uintersect(3), array_uintersect_assoc(3), array_uintersect_uassoc(3).
PHP Documentation Group ARRAY_UDIFF(3)