Declaring in variables [closed]

You need to call global $variable; before you can use the variable. Try the code below instead for that line.

// setup your global scope here

global $icon_var;

// set the new value in global scope

$icon_var = get_post_meta($menu_item->ID, '_menu_item_custom', true);  

// then use the variable

$menu_list .= "\t\t\t\t\t<li><a href=\"$url\">$icon_var<span>$title</span></a></li>\n";

DYNAMIC GLOBAL VARIABLE NAME

If you Created your data in a global variable and now you want to access it with a dynamic name reference then use the $GLOBALS directly.

// 'icon_home' set as global

global $icon_home;
$icon_home="<svg style="width:24px;height:24px" viewBox="0 0 24 24"> <path fill="#000000" d="M10,20V14H14V20H19V12H22L12,3L2,12H5V20H10Z"></path></svg>";

// variable name retrieved dynamically

// 'icon_home';
$icon_var = get_post_meta($menu_item->ID, '_menu_item_custom', true); 
$icon = $GLOBALS [$icon_var]; 

// output icon

echo "\t\t\t\t\t<li><a href=\"$url\">$icon<span>$title</span></a></li>\n";