Related Content
Recreating Spotify Wrapped In PHP
I quite like the end of the year report from Spotify that they call "Wrapped". This is a little application in which they tell you what your favorite artist was and what sort of genres you listened to the most during the year.
Should A Constructor Throw An Exception?
Let's say you had a class that you wanted to use, but there was some sort of error in creating the object. This might be that the wrong parameters were passed, or the third party service (eg. a database) wasn't available at the time of creation.
PHP Question: Variable Reference
Question
What does the following code print out?
function arrayPrint($array)
{
echo implode(' ', $array);
}
$arrayA = [1, 2, 3];
$arrayB = $arrayA;
$arrayB[1] = 0;
arrayPrint($arrayA);
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.
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