PHP 8.4.24 Released!

Voting

: min(eight, eight)?
(Example: nine)

The Note You're Voting On

c dot smith at fantasticmedia dot co dot uk
2 years ago
If you must utilise this knowing that a variable may be unset, then you need to use an alternative method.

So instead of the following:

<?php
$var1 = "lorem";
$var2 = "ipsum";
$result = compact('var1', 'var2', 'unsetvar');
?>

Consider the following:

<?php
$var1 = "lorem";
$var2 = "ipsum";
$result = [];
foreach( ['var1', 'var2', 'unsetvar'] as $attr ) {
    if ( isset( $$attr ) ) {
        $result[ $attr ] = $$attr;
    }
}
?>

<< Back to user notes page

To Top