-1

I want to concatenate values like this

var unavailableDates = ["9-3-2018", "14-3-2018", "15-3-2012"];

i tried to make it like these but it throws error the given is my code.

var unavailableDates = [<?php foreach($lead as $l){ $arrval = $l['followup_date']; "$arrval" } ?>];
Eddie
  • 26,593
  • 6
  • 36
  • 58
sooraj s pillai
  • 866
  • 2
  • 17
  • 39

1 Answers1

1

The way i understand your code, you are trying to convert a php multi dimensional array to a simple js array.

You have to use json_encode and array_column

<?php
    $lead = array(
        array(
            'followup_date' => '9-3-2018',
        ),
        array(
            'followup_date' => '14-3-2018',
        ),
        array(
            'followup_date' => '15-3-2012',
        )
    );
?>

<script>
    var unavailableDates = <?php echo json_encode( array_column( $lead, 'followup_date') ); ?>;
    console.log( unavailableDates );
</script>

This will result to

["9-3-2018", "14-3-2018", "15-3-2012"]

http://php.net/manual/en/function.array-column.php

Eddie
  • 26,593
  • 6
  • 36
  • 58