Easy swapping PHP variables

February 18, 2022

Using list() function to swap variables values without adding more variables.

$url = 'blog:5';
list($type, $id) = explode(':', $url);
// in case that the url is 5:block
if (!is_numeric($id)) {
    list($type, $id) = [$id, $type];
}

posted in php by Ivan Gospodinow

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment


Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /home/c2kblate/sites/ivangospodinow.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048
 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org