0
Is it possible to place an if/Else condition inside a foreach? Below part of a code, where you enter the date range in the bank via $_POST. The question is: Is it possible to place an if/Else within this range? Ex: If it is Saturday, do not fill, or if it is Saturday fill in a certain time.
$start = new DateTime($_POST["data1"]);
$end = new DateTime($_POST["data2"]);
$interval = new DateInterval("P1D");
$period = new DatePeriod($start, $interval, $end);
foreach($period as $p)
{
$x =$p->format('Y-m-d');
$sql ="INSERT INTO dt(data) VALUES('$x')";
$x = $connection->prepare($sql);
if($x->execute())
Your problem was not very clear. Could give details?
– GeekSilva
Sure! I’m taking a date range and entering it into the bank as the code shows. I do this by means of a foreach that will catch this interval of datePeriod. I would like to put conditions within the capture of this date range. For example, if in this interval one day of the week falls as Saturday jumps, it does not record.Just an example
– Almino