3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => [ "id" => 1, "name" => "Sammy", "phone" => "2348055643322", "email" => "sammy@abc.com" ], 1 => [ "id" => 2, "name" => "Saheed", "phone" => "", "email" => "saay@aol.com" ], 2 => [ "id" => 3, "name" => "Edwin", "phone" => "2348099993322", "email" => "eddy@gmail.com" ], 3 => [ "id" => 3, "name" => "Jonadab", "phone" => "2348066773322", "email" => "jonadab@gmail.com" ], 4 => [ "id" => 3, "name" => "Mercy", "phone" => "", "email" => "mercy@sysnet.com" ] ]; $start = microtime(true); $phone = array_filter(array_column($array, "phone")); $filtered = array_intersect_key($array, $phone); Echo "array_intersect_key: " . (microtime(true)-$start)*1000; $start = microtime(true); $column = 'phone'; //column to filter $result = array_filter($array, function($o) use($column) { return trim( $o[$column] ) !== '' && $o[$column] !== null; }); Echo "\n\narray_filter: " . (microtime(true)-$start)*1000; $start = microtime(true); foreach ($array as $index => $row) { if (strlen($row['phone'])) { // keep the original index $response [$index]= $row; } } Echo "\n\nforeach: " . (microtime(true)-$start)*1000; $start = microtime(true); $reulting_array = array_filter($array, function ($entry) { return !empty($entry['phone']); }); Echo "\n\narray_filter by SaAy: " . (microtime(true)-$start)*1000;
Output for git.master
array_intersect_key: 0.0059604644775391 array_filter: 0.027894973754883 foreach: 0.003814697265625 array_filter by SaAy: 0.0030994415283203
Output for git.master_jit
array_intersect_key: 0.0061988830566406 array_filter: 0.024080276489258 foreach: 0.003814697265625 array_filter by SaAy: 0.0019073486328125
Output for rfc.property-hooks
array_intersect_key: 0.0050067901611328 array_filter: 0.015974044799805 foreach: 0.0040531158447266 array_filter by SaAy: 0.0028610229492188

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
62.05 ms | 408 KiB | 5 Q