• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript jqeury why does my array not exist?


Well-Known Coder
Hello I'm trying to loop through my php array in jqeury but when I do that it days it doesn't exist. this is weird to me because I'm able to use the array to create an variable in jqeury. I need a loop that starts at the first date, and adds 1 day until it reaches the end date.
the php code
$huis_ID = $_GET['ID'];
 $sql = "SELECT start_datum, eind_datum FROM reserveringen WHERE huis_ID = ?";
 $stmt = $conn->prepare($sql);
 $stmt->bind_param("i", $huis_ID);
 $result = $stmt->get_result();
 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
         $start_datum = date('d-m-Y', strtotime($row['start_datum']));
         $eind_datum = date('d-m-Y', strtotime($row['eind_datum']));
        array_push($arraysession, $start_datum, $eind_datum);


  var dates = <?php echo $array_to_json ?>; // this part works
    function disableDates(date) {
        var string = $.datepicker.formatDate('dd-mm-yy', date);
// this doesn't work because it doesn't understand what $array_to_json is 
        for(var i = dates; i < <?php $array_to_json ?>. length ; i++){
        console. log(i);
        return [dates.indexOf(string) == -1];
In your variable naming the $array_to_json it includes "echo" whereas your for loop does not.

//Your var declaration and for loop
var dates = <?php echo $array_to_json ?>;
for(var i = dates; i < <?php $array_to_json ?>. length ; i++)

// Proper for loop name
var dates = <?php echo $array_to_json ?>;
for(var i = dates; i < <?php echo $array_to_json ?>. length ; i++)

Give that a shot and let us know
Top Bottom