I am trying to store values in a for loop as an array so I can access them outside them outside the loop.
foreach ($doctor->booking as $booking) {
$bookeddate = date('Y-m-d', strtotime($booking->booked_time));
if( $bookeddate == $end_date ) {
$booked_time[] = date('H:i a', strtotime($booking->booked_time));
}
}
foreach ($booked_time as $key ) {
echo $key;
}
This code keeps giving me an error "Undefined variable: booked_time"
if($bookeddate==$end_date){. Be sure to initialize the var as an empty array if you want to avoid that, or test withisset