3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); ini_set('display_errors', true); ini_set('html_errors', false); $cats = array( (object) array("term_id"=>"","name"=>"Film : FIILMTOFTWFUT : post-COLON2","slug" => "alphabetical-k-l-m-n-o ","term_group"=>5,"term_taxonomy_id"=>9,"taxonomy"=>"Myanmar","description"=>"69509","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=> "Country: Cambodia ","slug"=>"Media Relations","term_group"=>5,"term_taxonomy_id"=>7,"taxonomy"=>"Belgium","description"=>"14234","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Advertising","slug"=>"Quality Assurance","term_group"=>5,"term_taxonomy_id"=>1,"taxonomy"=>"Norfolk Island","description"=>"93236","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Finances","slug"=>"Legal Department","term_group"=>5,"term_taxonomy_id"=>5,"taxonomy"=>"Honduras","description"=>"74759","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Legal Department","slug"=>"Media Relations","term_group"=>1,"term_taxonomy_id"=>9,"taxonomy"=>"Namibia","description"=>"69625","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Sales and Marketing","slug"=>"Advertising","term_group"=>2,"term_taxonomy_id"=>4,"taxonomy"=>"Syria","description"=>"56469","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Finances","slug"=>"Media Relations","term_group"=>5,"term_taxonomy_id"=>8,"taxonomy"=>"Ethiopia","description"=>"74909","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Media Relations","slug"=>"Asset Management","term_group"=>5,"term_taxonomy_id"=>9,"taxonomy"=>"Indonesia","description"=>"17623","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Finances","slug"=>"Customer Relations","term_group"=>2,"term_taxonomy_id"=>3,"taxonomy"=>"Zimbabwe","description"=>"83249","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Sales and Marketing","slug" => "alphabetical-k-l-m-n-o ","term_group"=>1,"term_taxonomy_id"=>10,"taxonomy"=>"Faroe Islands","description"=>"03778","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Sales and Marketing","slug"=>"Sales and Marketing","term_group"=>7,"term_taxonomy_id"=>3,"taxonomy"=>"Latvia","description"=>"68525","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Accounting","slug"=>"Research and Development","term_group"=>9,"term_taxonomy_id"=>7,"taxonomy"=>"Bouvet Island","description"=>"18959","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Asset Management","slug"=>"Advertising","term_group"=>1,"term_taxonomy_id"=>9,"taxonomy"=>"Tajikistan","description"=>"94796","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Tech Support : arstatf","slug"=>"Accounting","term_group"=>5,"term_taxonomy_id"=>7,"taxonomy"=>"Côte D'Ivoire (Ivory Coast)","description"=>"24209","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Film : FIILMTOFTWFUT : post-COLON2","slug"=>"Human Resources","term_group"=>9,"term_taxonomy_id"=>3,"taxonomy"=>"Ukraine","description"=>"77647","parent"=>"","count"=>"1"), (object) array("term_id"=>"","name"=>"Media Relations","slug"=>"Customer Service","term_group"=>6,"term_taxonomy_id"=>7,"taxonomy"=>"Maldives","description"=>"97264","parent"=>"","count"=>"1") ); //list($k, $v) = //print_r(explode(' ',$cat->name,2)); //$result[$k]=$v; // $result[] = array_map(function($v){ // return explode(" ", $v); // }, $cat); function getStuff($o) { //$z= get_object_vars($o); //print $o->name; $o = (array)$o; $nameParts = explode(' ',$o['name'],2); list($o['category'], $o['name']) = $nameParts; return $o=(object)$o; ; } $a=array_map('getStuff', $cats); //var_dump($a); foreach($a as $element) { $categories[$element->category][] = $element; } /* $filtered_categories = array(); foreach($a as $element => $value) { $filtered_categories[$value->category][$key] = $value; echo "{$filtered_categories[$value->category][$key]}, {$value}\n"; } ksort($filtered_categories, SORT_REGULAR); //foreach ($filtered_categories as $key => $val) { // echo "$key = $val\n"; //} */ ?>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Undefined array key 1 in /in/F6Ms5 on line 47 Warning: Undefined array key 1 in /in/F6Ms5 on line 47 Warning: Undefined array key 1 in /in/F6Ms5 on line 47 Warning: Undefined array key 1 in /in/F6Ms5 on line 47 Warning: Undefined array key 1 in /in/F6Ms5 on line 47
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Undefined array key 1 in /in/F6Ms5 on line 47 Warning: Undefined array key 1 in /in/F6Ms5 on line 47 Warning: Undefined array key 1 in /in/F6Ms5 on line 47 Warning: Undefined array key 1 in /in/F6Ms5 on line 47 Warning: Undefined array key 1 in /in/F6Ms5 on line 47
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Notice: Undefined offset: 1 in /in/F6Ms5 on line 47 Notice: Undefined offset: 1 in /in/F6Ms5 on line 47 Notice: Undefined offset: 1 in /in/F6Ms5 on line 47 Notice: Undefined offset: 1 in /in/F6Ms5 on line 47 Notice: Undefined offset: 1 in /in/F6Ms5 on line 47
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Notice: Undefined offset: 1 in /in/F6Ms5 on line 47 Notice: Undefined offset: 1 in /in/F6Ms5 on line 47 Notice: Undefined offset: 1 in /in/F6Ms5 on line 47 Notice: Undefined offset: 1 in /in/F6Ms5 on line 47 Notice: Undefined offset: 1 in /in/F6Ms5 on line 47

preferences:
310.18 ms | 402 KiB | 458 Q