3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class ArrayFilter { private $arr = array(); private $field; private $value; function __construct($array, $field, $value) { $this->arr = $array; $this->field = $field; $this->value = $value; } function dataCorrect($arr) { echo("\n->> ".print_r($array)." <<-\n"); $field = $this->field; $val = $this->value; return $arr[$field] == $val; } } $fields = array( 'OrgType' => array( 'label' => 'Субъект права' ,'showType' => array(0, 1, 2) ,'sort' => 1 ) ,'OrgName' => array( 'label' => 'Полное наименование организации' ,'showType' => array(0, 1, 2) ,'sort' => 1 ) ,'OrgNameSmall' => array( 'label' => 'Краткое наименование организации' ,'showType' => array(0, 1, 2) ,'sort' => 1 ) ,'Surname' => array( 'label' => 'Фамилия' ,'showType' => array(1, 2) ,'sort' => 1 ) ,'Name' => array( 'label' => 'Имя' ,'showType' => array(1, 2) ,'sort' => 1 ) ,'Patronymic' => array( 'label' => 'Отчество' ,'showType' => array(1, 2) ,'sort' => 1 ) ,'INN' => array( 'label' => 'ИНН' ,'showType' => array(0, 1, 2) ,'sort' => 1 ) ,'KPP' => array( 'label' => 'КПП' ,'showType' => array(0, 1, 2) ,'sort' => 1 ) ,'OGRN' => array( 'label' => 'ОГРН' ,'showType' => array(0, 1, 2) ,'sort' => 1 ) ,'EtpRole' => array( 'label' => 'Роль на ЭТП' ,'showType' => array(0, 1, 2) ,'sort' => 1 ) ,'UrAddressUnparsed' => array( 'label' => 'Юридический адрес' ,'showType' => array(0, 1, 2) ,'sort' => 1 ) ,'UrAddress' => array( 'label' => 'Юридический адрес' ,'showType' => array() ,'sort' => 1 ) ,'PostAddressUnparsed' => array( 'label' => 'Фактический адрес' ,'showType' => array(0, 1, 2) ,'sort' => 1 ) ,'PostAddress' => array( 'label' => 'Фактический адрес' ,'showType' => array() ,'sort' => 1 ) // директор ,'DirName' => array( 'label' => 'ФИО руководителя' ,'showType' => array(0, 1) ,'sort' => 2 ) ,'DirDol' => array( 'label' => 'Должность' ,'showType' => array(0, 1) ,'sort' => 2 ) ,'DirDivision' => array( 'label' => 'Структурное подразделение' ,'showType' => array(0) ,'sort' => 2 ) ,'DirBasis' => array( 'label' => 'Вид документа, на основании которого действует руководитель' ,'showType' => array(0) ,'sort' => 2 ) ,'DirEmail' => array( 'label' => 'E-mail директора' ,'showType' => array(0, 1) ,'sort' => 2 ) // контактное лицо ,'KontName' => array( 'label' => 'ФИО контактного лица' ,'showType' => array(0, 1, 2) ,'sort' => 3 ) ,'KontPhone' => array( 'label' => 'телефон контактного лица' ,'showType' => array(0, 1, 2) ,'sort' => 3 ) ); // задаем имя поля и значение которое ищем $field = 'sort'; $value = '3'; // сам механизм фильтрации массива глубина 1 уровень $out = array_filter( $fields, array( new ArrayFilter($fields, $field, $value), 'dataCorrect' ) ); print_r($out);
Output for 5.0.4 - 7.1.0
Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Array ( [KontName] => Array ( [label] => ФИО контактного лица [showType] => Array ( [0] => 0 [1] => 1 [2] => 2 ) [sort] => 3 ) [KontPhone] => Array ( [label] => телефон контактного лица [showType] => Array ( [0] => 0 [1] => 1 [2] => 2 ) [sort] => 3 ) )
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Notice: Undefined variable: array in /in/BeMCp on line 16 ->> 1 <<- Array ( [KontName] => Array ( [label] => ФИО контактного лица [showType] => Array ( [0] => 0 [1] => 1 [2] => 2 ) [sort] => 3 ) [KontPhone] => Array ( [label] => телефон контактного лица [showType] => Array ( [0] => 0 [1] => 1 [2] => 2 ) [sort] => 3 ) )
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/BeMCp on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/BeMCp on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/BeMCp on line 4
Process exited with code 255.