Related Content
Generating Histogram Colour Analysis Graphs From Images In PHP
If you've ever looked at the settings in a digital camera, or have experience with image processing programs like GIMP, then you may have seen a colour histogram. This is a simple graph that shows the amount of different shades of colour are present in the image.
PHP:CSI - To Switch, Or Not To Switch?
I was writing unit tests for a API mapping function recently and came across this interesting issue. The code I was writing tests for was in a legacy codebase that I was making changes to, and it made sense to have some unit tests in there before I started work to ensure everything worked before and after.
Drupal 9: Generating Header Images For Pages Of Content Using PHP
Embedding image within pages of content helps both within the design of the page and when shared on social media. If you set up meta tags to point at a particular image then that image will appear when the page is shared on social media. This makes your page stand out more.
Using PSR-4 With Composer
The PHP Standards Recommendations (called PSR) are a set of standards that aim to make certain aspects of working with PHP easier.
Generating A PDF From A Web Page Using PHP And Chrome
Generating a PDF document from a web page through PHP can be problematic. It's often something that seems quite simple, but actually generating the document can be difficult and time consuming.
PHP:CSI - Date Is Less Than One Month Ago
Working with logic surrounding dates can sometimes be difficult and it's fairly common to come across really subtle date and time based bugs.
I was recently shown a bug in a PHP application that looks like it should be working at face value, but doesn't actually produce the correct result.
Comments
Submitted by James Bower on Mon, 09/07/2009 - 21:17
Permalink... $var1 = (strstr($string, 'a') && false !== $var2 = strstr($string, 'b') && false !== $var3 = strstr($string, 'c')) ... $var2 = (strstr($string, 'b') && false !== $var3 = strstr($string, 'c'))
to get expected behaviour all one needs is enclosing assignments within ().if ( false !== ($var1 = strstr($string, 'a')) && false !== ($var2 = strstr($string, 'b')) && false !== ($var3 = strstr($string, 'c'))) { var_dump($var1, $var2, $var3); }
also by doing that - in theory - you're helping compiler (for tiny speedup) so it doesn't need to find out operator precedence, just eval from insidemost statement(s).Submitted by Mirek Suk on Tue, 09/28/2010 - 12:08
PermalinkSubmitted by philipnorton42 on Wed, 09/29/2010 - 08:56
PermalinkSubmitted by Jim on Sun, 11/07/2010 - 23:09
PermalinkThis works too:
if( !($val = $arg) ) { $val = 'default'; }
Submitted by Frank on Mon, 05/02/2011 - 17:52
PermalinkSubmitted by Vishal on Sun, 05/17/2015 - 09:24
PermalinkSubmitted by Jesus on Tue, 03/20/2018 - 14:55
PermalinkSubmitted by philipnorton42 on Tue, 03/20/2018 - 15:19
PermalinkA gotcha worth highlighting, assigning a 0 is of course a falsy, so you can work around it as follows where NULL is returned when we really want to exit, and not on 0.
Submitted by Russ on Fri, 05/31/2019 - 18:18
PermalinkHi, I need help with below code
How to create variable with if multiple statement in php and print
and want to print as
Submitted by Sam on Fri, 05/15/2020 - 21:30
PermalinkSam,
For fixed payment types, you may be better off to assign an array with the options, with the code as key, and display name as value. That array could be filled from a database query on payment types allowed, which would then pick up when you add a new option, you don't then have to re-code so much.
That has no input validation etc, but might be a start.
Submitted by Peter H on Fri, 06/05/2020 - 12:24
PermalinkAdd new comment