Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End use function variables like wordpress Re: use function variables like wordpress

#80261
Makeshift
Member

I know that, but how do i get the function to get each variable passed using ampersands and equal signs like that?

I made this little script for it:

Code:
function _li($args){
$args = explode(‘&’, $args);

$args1 = $args[0];
$args1 = explode(‘=’, $args1);
$args1 = array($args1[0] => $args1[1]);
foreach($args1 as $key => $val){
if($key == ‘text’){$text = $val;}
elseif($key == ‘title’){$title = $val;}
elseif($key == ‘href’){$href = $val;}
}

$args2 = $args[1];
$args2 = explode(‘=’, $args2);
$args2 = array($args2[0] => $args2[1]);
foreach($args2 as $key => $val){
if($key == ‘text’){$text = $val;}
elseif($key == ‘title’){$title = $val;}
elseif($key == ‘href’){$href = $val;}
}

$args3 = $args[2];
$args3 = explode(‘=’, $args3);
$args3 = array($args3[0] => $args3[1]);
foreach($args3 as $key => $val){
if($key == ‘text’){$text = $val;}
elseif($key == ‘title’){$title = $val;}
elseif($key == ‘href’){$href = $val;}
}
}

(there’s more to it, but this splits the function variable)

and the usage..

Code:
_li(‘text=Home&title=Go Back Home’);

but this will only take the first 3 variables, of course I can make it as many as I want, but every time i make a new function for something like this, I don’t wanna have to set it for how many variables it’s looking for…