foreach($arr as $el){
$what= $el->what;
if($what == 'img'){get_img();}
elseif($what == 'video'){get_video();
elseif($what == 'something'){get_something();}
}
How to say the above shortly, like this:
get_$what();
as in https://www.php.net/manual/en/functions.variable-functions.php
$func = 'foo';
$func(); // This calls foo()
so in your case:
foreach($arr as $el){
$what= $el->what;
$funcname = 'get_'.$what;
$funcname();
}
You can use parentheses
<?php
function ab(){echo 'ho';}
$foo='video';
('get_'.$foo)();
You could save the function name into a variable and then call that function dynamically by adding () to the variable. ( not sure if i said this right )
$yourFunction = 'get_';
$yourFunction .= 'img';
$value = $yourFunction();
// will execute get_img();