Related Content
Creating An Authentication System With PHP and MariaDB
Using frameworks to handle the authentication of your PHP application is perfectly fine to do, and normally encouraged. They abstract away all of the complexity of managing users and sessions that need to work in order to allow your application to function.
Creating Sparklines In PHP
A sparkline is a very small line graph that is intended to convey some simple information, usually in terms of a numeric value over time. They tend to lack axes or other labels and are added to information readouts in order to expand on numbers in order to give them more context.
PHP:CSI - Improving Bad PHP Logging Code
I read The Daily WTF every now and then and one story about bad logging code in PHP stood out to me. The post looked at some PHP code that was created to log a string to a file, but would have progressively slowed down the application every time a log was generated.
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.
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