Code snippets
You will find here 19 code snippets I find useful so I don't have to Google ™ or Stackoverflow ™ them when I need. There are also code snippets I always forget! 😁 Sometimes, related links to the code will be available. The main difference with other random snippets you will find on the web is that in most cases (for the Symfony related ones) you will be able to run them directly from this website to check the output so you can verify it works as expected ™.
This snippet shows how to pick random keys of an array with PHP. This pickArrayKeys() is very convenient and, unlike most other ra...
PHP
Published on 2023-09-13 • Modified on 2023-09-13
I continue my series about PHP 8.2 and the randomizer class. This time, we see how to shuffle an array thanks to the shuffleArray(...
PHP
Published on 2023-09-11 • Modified on 2023-09-11
This snippet shows how to index a PHP array of objects by their class name. We can use the array_reduce function instead of doing ...
PHP
Published on 2023-06-17 • Modified on 2023-06-17
This snippet shows how to order a PHP array of objects by a given property. The sort function is in the snippet class, but if we w...
PHP
Published on 2023-05-31 • Modified on 2023-05-31
This snippet shows how to generate an array with the same keys and values with PHP. This is the first time I have tried chatGPT to...
PHP
Published on 2022-12-10 • Modified on 2022-12-10
This snippet shows how to create a fixed-size array with PHP. We can use the SplFixedArray class. It is interesting to use this s...
PHP
Published on 2022-11-11 • Modified on 2022-11-11
This snippet shows how to test if an array is a list with PHP. This function was introduced in PHP 8.1, before we had to do this m...
PHP
Published on 2022-09-10 • Modified on 2022-09-10
In this snippet, we see how to filter a Doctrine collection. We have this filter() function we can call with a closure. Here I use...
Doctrine
Published on 2022-03-19 • Modified on 2022-03-19
In this snippet, we see how to get the first item of an array with PHP. This is a classic snippet every PHP developer had to use o...
PHP
Published on 2022-01-21 • Modified on 2022-01-21
This snippet shows how to create to a "n" dimensions matrix with PHP. In the previous snippet, we saw how to create a two dimensi...
PHP
Published on 2022-01-01 • Modified on 2022-01-01