array_filter(
$array,
function($row) {
return $row['height'] > 173;
}
);
$scoolChild = array(
'Антон' => 172,
'Семен' => 165,
'Лена' => 189,
'Иван' => 171,
'Петр' => 182,
'Сидор' => 176,
'Аня' => 180,
'Таня' => 179,
'Маня' => 171
);
$tall = array_filter(
$scoolChild,
function($height) {
return $height > 173;
}
);
$data = <<<XML
<settings>
<one type="gui" subtype="fullscreen">true</one>
<two type="gui" subtype="alphablend">255</two>
</settings>
XML;
function parse_xml($data)
{
$result = [];
$xml = simplexml_load_string($data);
/** @var SimpleXMLElement $node */
foreach ($xml as $key => $node) {
$value = [];
foreach ($node->attributes() as $k => $v) {
$value[$k] = (string) $v;
}
$value['value'] = (string) $node;
$result[$key] = $value;
}
return $result;
}
var_dump(parse_xml($data));
array(2) {
'one' =>
array(3) {
'type' =>
string(3) "gui"
'subtype' =>
string(10) "fullscreen"
'value' =>
string(4) "true"
}
'two' =>
array(3) {
'type' =>
string(3) "gui"
'subtype' =>
string(10) "alphablend"
'value' =>
string(3) "255"
}
}
$language_iso2 = preg_replace_callback(
'/^([\w])/e',
function($m) {
return strtoupper($m[1]);
},
$language->iso2
);
Модификатор /e теперь считается устаревшим. Используйте функцию preg_replace_callback(). Смотрите документацию PREG_REPLACE_EVAL с дополнительной информацией и описанием проблем с безопасностью.
<?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);