字符串没有爆炸

string is not getting exploded

这是我的代码,其中 explode 函数没有得到 correctly.code 看起来像这样

 <div id="demo-1" data-zs-src='[<?php foreach( $slides as $slide ){?>"<?php echo base_url();?>uploads/<?php echo $slide->image;?>"<?php }?>]' data-zs-overlay="dots">
<div class="demo-inner-content">
  <h1><span>Tasty</span> & <span>Healthy</span></h1>
  <p>For those who have taste for life.</p>
</div>

我的结果是这样的

<div id="demo-1" data-zs-src='["http://localhost/fahiz_kitchen/uploads/upload-file1496902770.jpg""http://localhost/fahiz_kitchen/uploads/upload-file1496901910.gif""http://localhost/fahiz_kitchen/uploads/upload-file1496901900.jpg""http://localhost/fahiz_kitchen/uploads/upload-file1496901887.jpg"]' data-zs-overlay="dots">
<div class="demo-inner-content">
  <h1><span>Tasty</span> & <span>Healthy</span></h1>
  <p>For those who have taste for life.</p>
</div>
</div>  

我想在结果之间加上逗号,这意味着我的结果应该是这样的

<div id="demo-1" data-zs-src='["http://localhost/fahiz_kitchen/uploads/upload-file1496902770.jpg",
"http://localhost/fahiz_kitchen/uploads/upload-file1496901910.gif",
"http://localhost/fahiz_kitchen/uploads/upload-file1496901900.jpg",
"http://localhost/fahiz_kitchen/uploads/upload-file1496901887.jpg"

喜欢就改。

 $data = [<?php 
    foreach( $slides as $slide ){
     ?>"<?php echo base_url();?>uploads/<?php echo $slide->image;?>",
   <?php }?>];
$finaldata = rtrim($data, ',');

<div id="demo-1" data-zs-src="'.$finaldata.'" data-zs-overlay="dots">
<div class="demo-inner-content">
  <h1><span>Tasty</span> & <span>Healthy</span></h1>
<p>For those who have taste for life.</p>
</div>

你正在启动php里面已经启动了它。

请使用这个;

<?php foreach( $slides as $slide ){ 
     $images= base_url()."uploads/". $slide->image;
     var_dump($images);
     $arr= explode(',',$images);
     print_r($arr);
}

?>

经过一些修改后我得到了结果,使用的代码如下

<?php foreach ( $slides as $slide ) {
$data[] = $images='"'.base_url()."uploads/". $slide->image.'"';
$y=implode(',',$data);
}?>
<div id="demo-1" data-zs-src='[<?php echo $y;?>]' data-zs-overlay="dots">
<div class="demo-inner-content">
  <h1><span>Tasty</span> & <span>Healthy</span></h1>
  <p>For those who have taste for life.</p>
</div>