title: How to get values separated with comma from database using PHP
body: <p>I have four files named comma separated in one field in database like this <code>file1</code>,<code>file2</code>,<code>file3</code>,<code>file4</code>. It may change depending on files uploading. User can upload maximum 4 files, minimum one file. But I was not able to get it. I used explode but it's taking too long.</p>
  
  <p>I am using this code:</p>
  
  <pre><code>      $imagefiles = $row["imagefiles"];
  
  
        $cutjobs = explode(",", $imagefiles);
        $cutjobs1 = count($cutjobs);
  
        $image1 = $cutjobs[0];
        $image2 = $cutjobs[1];
        $image3 = $cutjobs[2];
        $image4 = $cutjobs[3];
  
        if (empty($image1)) {
          $imagefiles1 = "";
        } else {
          $imagefiles1 = 'http://projects.santabantathegreat.com/glassicam/uploads/'.$registerid.
          "/".$viewjobsid.
          "/".$image1;
        }
  
        if (empty($image2)) {
          $imagefiles2 = "";
        } else {
          $imagefiles2 = 'http://projects.santabantathegreat.com/glassicam/uploads/'.$registerid.
          "/".$viewjobsid.
          "/".$image2;
        }
        if (empty($image3)) {
          $imagefiles3 = "";
        } else {
          $imagefiles3 = 'http://projects.santabantathegreat.com/glassicam/uploads/'.$registerid.
          "/".$viewjobsid.
          "/".$image3;
        }
        if (empty($image4)) {
          $imagefiles4 = "";
        } else {
          $imagefiles4 = 'http://projects.santabantathegreat.com/glassicam/uploads/'.$registerid.
          "/".$viewjobsid.
          "/".$image4;
        }
      }
  
      $data[] = array( 'imagearray' =&gt; array($imagefiles, $imagefiles1, $imagefiles2, $imagefiles3));
  
  
    }
    echo json_encode($data);
  }  
  </code></pre>
  
  <p>I am getting output like this :</p>
  
  <pre><code>[{"imagearray":["http:\/\/projects.santabantathegreat.com\/glassicam\/uploads\/60\/30\/file1.jpg","http:\/\/projects.santabantathegreat.com\/glassicam\/uploads\/60\/30\/file2.jpg",""]}]
  </code></pre>
  
  <p>If you see this imageArray last one is getting ""  that means some in <code>file1</code>, <code>file2</code>, <code>file3</code>, <code>file4</code> one name is missing so I want to show if any filename is not there means I don't want to show null values with ""</p>
  
  <p>i have a field with file1,file2,file3,file4 so times we will have file1,file3 then remaining will not there so i want to count file name separated with commas and if file1 is there is should print that if file3 is there not then it shouldn't show with ""</p>