3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Your code here! use Illuminate\Support\Collection; $word_list = ["banana", "peach", "banana", "berry", "grape", "melon", "orange", "apple", "banana","apple"]; $word_list2 = []; foreach ($word_list as $word){ $words_collection = collect(); $words_collection->put('word', $word); $words_collection->put('score', 5); array_push($word_list2, $word); } // continue; // } // array_push($words_rank, array("word"=>$word, "appear_of_num"=>$words_rank[$word]["appear_of_num"] + 1)); // } $words_rank = array_count_values($word_list2); // print_r($words_rank); arsort($words_rank); // print_r($words_rank); print_r(array_slice($words_rank, 0, 5)); ?>
Output for 7.3.0 - 7.3.30, 7.4.0 - 7.4.23, 8.0.0 - 8.0.11, 8.1rc1
Fatal error: Uncaught Error: Call to undefined function collect() in /in/D7NKD:12 Stack trace: #0 {main} thrown in /in/D7NKD on line 12
Process exited with code 255.

preferences:
17.91 ms | 459 KiB | 5 Q