How to find the last day of the month from date?
t returns the number of days in the month of a given date (see the docs for date): $a_date = “2009-11-23”; echo date(“Y-m-t”, strtotime($a_date));
t returns the number of days in the month of a given date (see the docs for date): $a_date = “2009-11-23”; echo date(“Y-m-t”, strtotime($a_date));
A simpler answer. function ($quantity) use ($tax, &$total) { .. }; The closure is a function assigned to a variable, so you can pass it around A closure is a separate namespace, normally, you can not access variables defined outside of this namespace. There comes the use keyword: use allows you to access (use) the … Read more
PHP 7 standard library provides the random_bytes($length) function that generate cryptographically secure pseudo-random bytes. Example: $bytes = random_bytes(20); var_dump(bin2hex($bytes)); The above example will output something similar to: string(40) “5fe69c95ed70a9869d9f9af7d8400a6673bb9ce9” More info: http://php.net/manual/en/function.random-bytes.php PHP 5 (outdated) I was just looking into how to solve this same problem, but I also want my function to create a … Read more
If you’re looking for a way to normalize a date into MySQL format, use the following $phpdate = strtotime( $mysqldate ); $mysqldate = date( ‘Y-m-d H:i:s’, $phpdate ); The line $phpdate = strtotime( $mysqldate ) accepts a string and performs a series of heuristics to turn that string into a unix timestamp. The line $mysqldate … Read more
empty() needs to access the value by reference (in order to check whether that reference points to something that exists), and PHP before 5.5 didn’t support references to temporary values returned from functions. However, the real problem you have is that you use empty() at all, mistakenly believing that “empty” value is any different from … Read more
Only double quoted strings interpret the escape sequences \r and \n as ‘0x0D’ and ‘0x0A’ respectively, so you want: “\r\n” Single quoted strings, on the other hand, only know the escape sequences \\ and \’. So unless you concatenate the single quoted string with a line break generated elsewhere (e. g., using double quoted string … Read more
As per the documentation, you need to specify true as the second argument if you want an associative array instead of an object from json_decode. This would be the code: $result = json_decode($jsondata, true); If you want integer keys instead of whatever the property names are: $result = array_values(json_decode($jsondata, true)); However, with your current decode … Read more
$x = new stdClass(); A comment in the manual sums it up best: stdClass is the default PHP object. stdClass has no properties, methods or parent. It does not support magic methods, and implements no interfaces. When you cast a scalar or array as Object, you get an instance of stdClass. You can use stdClass … Read more
I think the best equivalent to PHP’s var_dump($foo, $bar) is combine print with vars: print vars(foo),vars(bar)
Multi-threading is possible in php Yes you can do multi-threading in PHP with pthreads From the PHP documentation: pthreads is an object-orientated API that provides all of the tools needed for multi-threading in PHP. PHP applications can create, read, write, execute and synchronize with Threads, Workers and Threaded objects. Warning: The pthreads extension cannot be … Read more