Skip to content

Instantly share code, notes, and snippets.

@N-Molham
Forked from jamesscaggs/import-function.php
Last active August 18, 2016 12:28
Show Gist options
  • Save N-Molham/7d05c6430e7aea761eed0d6a99232d44 to your computer and use it in GitHub Desktop.
Save N-Molham/7d05c6430e7aea761eed0d6a99232d44 to your computer and use it in GitHub Desktop.
<?php
function my_condition( $original )
{
if ( is_numeric( $original ) )
$original = absint( trim( $original ) ) >= 2016 ? 'new' : 'used';
$makes = array(
'cons' => 'Used',
'used' => 'Used',
'U' => 'Used',
'new' => 'New',
'N' => 'New',
);
return match_convert( $original, $makes );
}
function match_convert( $original , $words = '' , $default = 'Used' )
{
if ( empty( $words ) )
return $default;
foreach ( $words as $matching_word => $replacement )
{
if ( false !== strpos( mb_strtolower( $original ), mb_strtolower( $matching_word ) ) )
return $replacement;
}
return $default;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment