Skip to content

Tag: php

Sort array and keep values of keys

I have an array that looks like this: and I would like to sort the teams by the number of points each team has. I have tried this: But that approach overrides the keys containing the teamnames and returns: Is there any way to sort the array without overwriting the teamnames as the array keys? Answer Use the u…

How to get total time from several date ranges in php

I have several date ranges in form of DateTime $begin, DateTime $end. Those ranges can overlap in every possible way: etc. What I am trying to do is to get length (in seconds or DateInterval) of those ranges between start of the first one and the end of the latest one (fourth in the case above), excluding reg…

WordPress database error MySQL server has gone away for query

I get this error so frequently that the php_error log file increases 1MB every 2 seconds. and the site is very slow. I have tried to add this line to wp-db.php but it did not help. The web server is IIS 7, latest version of mysql and wordpress Answer This trick will work for all WordPress versions. Open your …

How to return a line number in a PHP script

Is it possible for a PHP script to return a line number in which some command is called? I’m having trouble describing what I want so maybe an example. I have PHP code that calls MySQL on many occasions. In line 49 is: The text “line 49” I wrote manually. Is it possible to get this number &#…