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] =>
)
bbvicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard QuadlingSenior Software DeveloperCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bbvicAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.