3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $object1 = new stdClass(); $object1->id = 1; $object1->nome = 'B'; $object2 = new stdClass(); $object2->id = 1; $object2->nome = 'A'; $dados = array($object1, $object2); function orderData(array $data) { $alphabetic = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'z'); $asc = array(); foreach ($alphabetic as $keyAlpha => $valueAlpha) { foreach ($data as $key => $value) { $letter = $value->nome; $letter = $letter['0']; var_dump($letter); if ($valueAlpha == $letter || strtoupper($letter) == strtoupper($letter)) { $asc[$key] = $value; } } } return $asc; } var_dump( orderData($dados) );
based on lJplU
Output for 5.1.0 - 7.1.0
string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" string(1) "B" string(1) "A" array(2) { [0]=> object(stdClass)#1 (2) { ["id"]=> int(1) ["nome"]=> string(1) "B" } [1]=> object(stdClass)#2 (2) { ["id"]=> int(1) ["nome"]=> string(1) "A" } }
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/NVhMN on line 13
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/NVhMN on line 13
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_ARRAY, expecting ')' in /in/NVhMN on line 13
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/NVhMN on line 13
Process exited with code 255.