Easy swapping PHP vairables

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

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org