Search code examples
phparraysimplode

Implode array PHP


I have implode code like this :

$date_condition = implode(" AND a.date = ",$date_interval);

That array looks like this :

$date_interval = Array('2017-01-24','2017-01-25','2017-01-26');

This is what I want to expected become an output :

$date_condition = "'2017-01-24' AND a.date = '2017-01-25' AND a.date = '2017-01-26' ";

But from my code that I was try I just get output like this :

$date_condition = "2017-01-24 AND a.date = 2017-01-25 AND a.date = 2017-01-26";

How can I do that ?

Thank you.


Solution

  • Try this:

    $date_interval = Array('2017-01-24','2017-01-25','2017-01-26');
    $date_condition ="'". implode("' AND a.date = '",$date_interval)."'";
    echo $date_condition;
    

    DEMO HERE