/**
* Format number from 5251.25 to "5 251.25"
*
* @param num
* @returns {string}
*/
function numberFormat(num) {
if (!isFinite(num)) {
return num;
}
var parts = num.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
return parts.join('.');
}
<?php
namespace project {
abstract class Helper
{
public static function getMapper()
{
$self = new static();
$ref = new \ReflectionClass($self);
$ns = $ref->getNamespaceName();
$mapper = sprintf('%s\\Mapper', $ns);
return new $mapper($self);
}
}
}
namespace project\soft {
use project\Helper as BaseHelper;
class Helper extends BaseHelper
{
}
class Mapper
{
private $helper;
public function __construct($helper)
{
$this->helper = $helper;
}
}
}
namespace {
$mapper = \project\soft\Helper::getMapper();
var_dump($mapper);
}
<?php
$values = array(
'anyword_ui',
'random_ui',
'bad_string',
'foo_bar',
);
$filtered = preg_grep('/([a-z]\w+)\_((ui)+)/is', $values);
$count = count($filtered);
var_dump($count);