Paolo Pedrazzi Paolo Pedrazzi - 3 months ago 12
Ajax Question

Select only an array of dates Jquery datepicker

I have a

php array
that returns a available day of the week already converted in number this 1,2,5 for (Monday, Thursday, Friday).
Now i have function like this:

<script>
$(document).ready(function() {
$('#dataritiro').datepicker({
minDate: 0,
beforeShowDay: function(date) {
var day = date.getDay();
return [(day != 1 && day != 2)];
}
});
});
</script>


But i have trouble to use it with the provided array. I need that days available is dynamically fetched from the array that I pass trough
var days = <?php echo $days; ?>

Answer

You could use json_encode to translate your php array to a javascript array, then do something like @arun-p-johny suggested

var days = (<php echo json_encode($array); ?>);
...
return [days.indexOf(day) !== -1]