My code receives some results as shown below
$a=("es: $f, es1:$f1, es2:$f2, es3:$f3, es4:$f4, es5:$f5 ,es6:$f6, es7:$f7 " );
$array = explode(",", $a);
$output = print_r( $array, true ) ;
$longitud = count($array);
//echo"$longitud";
for($i=0; $i<$longitud; $i++)
{
echo $array[$i];
echo "<br>";
}
when i do this i get :
One of the things that I tried without result is to obtain only the values that they have, in this case it would be es2:2019-09-30 and es7:2019-09-29 placing an if inside the for, if anyone could help me. Thank you very much
To check if it is a date you can use
checkdate
enphp
, taking care to properly order the day, month and year elements based on the date format of your data. You can see more detail here .I add a test example with your code:
Result: There is no date type element is:
Another possible solution would be making use of the function
validateDate
proposed in the PHP Manual Contribution Notes .What we will do here is:
es...
and the values will be what comes after them.validateDate
that will tell us if it is a date or not.Advantage
validateDate
makes use of the classDateTime
This would be the code:
Departure:
And in
$mData
we have an ordered associative array. If we do a test:Departure:
An array with only valid dates
Suppose that what interests us is to create an array with only the elements that have valid dates. We could do the following:
Departure: