• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

array

if ship_date is 0000-00-00, then it has to be empty.
if ship_date is 2006-04-21, then it has to be 04/21/2006.

How can i get those results based on the bottom code.

foreach($csvData as $row) {
             
       //$row[] = ('0000-00-00' != $row ) ? date('m/d/Y', strtotime($row)) : '';
       print_r($row);
                   fputcsv($fp,$row);
             }


result looks like

Array
(
    [0] => order_number
    [1] => LNnumber
    [2] => order_approval_status
    [3] => ship_date
    [4] => tracking_number
)
Array
(
    [0] => M0101
    [1] => KVTR
    [2] => 1
    [3] => 0000-00-00
    [4] =>
)
Array
(
    [0] => M0102
    [1] => KVTR-6
    [2] => 1
    [3] => 0000-00-00
    [4] =>
)
Array
(
    [0] => M0103
    [1] => KVTR-1
    [2] => 4
    [3] => 0000-00-00
    [4] =>
)
0
bbvic
Asked:
bbvic
  • 2
  • 2
1 Solution
 
Richard QuadlingSenior Software DeverloperCommented:
foreach($csvData as $row)
 {
 $row[3] = ('0000-00-00' != $row[3] ) ? date('m/d/Y', strtotime($row[3])) : '';
 print_r($row);
 fputcsv($fp,$row);
 }

Sorry. Didn't quite understand the other question.
0
 
bbvicAuthor Commented:
if i use,
foreach($csvData as $row)
 {
 $row[3] = ('0000-00-00' != $row[3] ) ? date('m/d/Y', strtotime($row[3])) : '';
 print_r($row);
 fputcsv($fp,$row);
 }


the result looks like
--------------------------
Array
(
    [0] => jupiter_order_number
    [1] => LNnumber
    [2] => order_approval_status
    [3] => 12/31/1969
    [4] => tracking_number
)
Array
(
    [0] => M^IND-IND0100~0101
    [1] => KVTR-6NYLQF
    [2] => 1
    [3] =>
    [4] =>
)
Array
(
    [0] => M^IND-IND0100~0102
    [1] => KVTR-6NYLQG
    [2] => 1
    [3] =>
    [4] =>
)
Array
(
    [0] => M^IND-IND0100~0103
    [1] => KVTR-6NYLQH
    [2] => 4
    [3] =>
    [4] =>
)



The result that I want

Array
(
    [0] => jupiter_order_number
    [1] => LNnumber
    [2] => order_approval_status
    [3] => ship_date
    [4] => tracking_number
)
Array
(
    [0] => M 0101
    [1] => KVTR-6
    [2] => 1
    [3] => 04/21/2006
    [4] =>
)
Array
(
    [0] => M0102
    [1] => KVTR-6NYLQG
    [2] => 1
    [3] =>
    [4] =>
)
Array
(
    [0] => M0103
    [1] => KVTRH
    [2] => 4
    [3] =>
    [4] =>
)
 
0
 
star_trekCommented:
The following code should work

foreach($csvData as $row1) {
           $row = array();
           foreach($row1 as $values) {
                if($values == '0000-00-00') {
                       $values = "";
                 else {
                       $values = preg_replace('/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/','\3/\4/\1\2',$values);
                  }
                  $row[] = $values;
           }
           print_r($row);
           fputcsv($fp,$row);
}
0
 
star_trekCommented:
oops missing a }
here is the correct one
foreach($csvData as $row1) {
           $row = array();
           foreach($row1 as $values) {
                if($values == '0000-00-00') {
                       $values = "";
                 } else {
                       $values = preg_replace('/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/','\3/\4/\1\2',$values);
                  }
                  $row[] = $values;
           }
           print_r($row);
           fputcsv($fp,$row);
}
0
 
bbvicAuthor Commented:
thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now