- var_dump: documentation ( source)
- preg_match: documentation ( source)
- preg_quote: documentation ( source)
- sprintf: documentation ( source)
<?php
function shouldUpdateUsername($source, $existing)
{
if ($source !== $existing)
{
$pattern = sprintf('/%s \[\d+\]/', preg_quote($source, '/'));
$processedBefore = preg_match($pattern, $existing) == 1;
$sourceAvailable = false;
return $sourceAvailable || $processedBefore;
}
return false;
}
var_dump(shouldUpdateUsername('Test', 'Test'));