Parsing a zero value from CSV

I’m trying to import some data from a CSV file into a WordPress plugin.

I’m having trouble when the value to be imported is ‘0’. Currently it converts a ‘0’ to NULL when saved in the database. The idea is to import a sport score ie. 2-0, which then gets parsed into an array.

Read More
$score = explode( '-', $result );

$home = trim($score[0]);
$away = trim($score[1]);

$goals = array( 'total' => array( 'home' => $home, 'away' => $away) );

update_post_meta( $id, 'total_score', serialize( $goals ) );

Can anybody suggest a solution, knowing me it’s probably something blindingly obvious but my brain has hit a brick wall!

Thanks in advance

Related posts

Leave a Reply

2 comments

  1. I have resolved the issue 🙂

    The original code was correct but a dodgy if/else statement was preventing the value for $score parsing correctly.

    The answers below, although not used, did help me slim down the possibilities, thanks.