Category Archives: PHP Solutions

How to Show Only Duplicate Values From an Array With PHP

If you have an array with duplicate values, sometimes you might need to show only non-unique elements. Here is a short code in PHP that will allow you to do this. <? $arr=array_map(“trim”, file(“file.txt”)); $nonuniq=array_unique(array_diff_assoc($arr, array_unique($arr))); ?> This will return unique array of duplicates. If you need to show all duplicated values, use this code. <? $arr=array_map(“trim”, file(“file.txt”));… Read More »

PHP: strtolower for Russian and Cyrillic

If you need to work with Russian text in PHP, you may notice that functions that are related to CaSe are not working as expected. I mean strtolower, strtouper, ucwords, and so on. In order to get what you need I suggest to use mb_convert functions. Here is the example: You can check reference table for functions, I… Read More »

PHP: strpos that takes array as an argument

Just found one useful function and would kike to share it. If you often use strpos, you might find this useful. This function will be useful if you need to find whether ANY element of array is presented in the source string. Else you have to either modify it, or create another one.