check array against each other, to determine response
Posted
by
Johnny
on Stack Overflow
See other posts from Stack Overflow
or by Johnny
Published on 2012-04-02T21:19:25Z
Indexed on
2012/04/02
23:28 UTC
Read the original article
Hit count: 188
php
So, I have an array that has 6 variables in it that I need to check against each other.. to determine what to return to the script calling the function.. All fields are of the datetime
type from the database they are derived from.
the fields: in1
out1
in2
out2
in3
out3
Array:
Array(
'in1' => '2012-04-02 10:00:00),
`out1` => '2012-04-02 14:00:00`,
`in2` => '2012-04-02 14:30:00`,
`out2` => '2012-04-02 18:00:00`,
`in3` => NULL,
`out3` => NULL
)
the response:
clocked_in
or clocked_out
What I need to figure out is, the best way to determine if the user is clocked in or clocked out by checking against this array..
so, if in1
, out1
and in2
are not NULL then the user would be clocked in.. if in1
is not NULL but out1
is NULL then the user would be clocked out, etc.. Anyone have any ideas on the easiest way to achieve this without too many if statements?
[WHAT WORKED]
for ($i=1; $i <= 3; $i++) {
if ($entities["in$i"] != NULL) {
$ents = "clocked_in";
if ($entities["out$i"] != NULL) {
$ents = "clocked_out";
}
if ($entities["out3"] != NULL) {
$ents = "day_done";
}
}
}
© Stack Overflow or respective owner