The php code.
public function GetProduct($id, $bc = '')
{
$productname = WHMCSProductProduct::getProductName($id);
$description = WHMCSProductProduct::getProductDescription($id);
$details = WHMCSProductProduct::find($id);
$pricing = $details->pricing();
if ($bc == '') {
$price = $pricing->first();
} else {
$price = $pricing->byCycle($bc);
if (is_null($price)) {
$price = $pricing->first();
}
}
return array(
'name' => $productname,
'description' => $description,
'price' => $price,
);
}
Output when i am using {$description} variable in tpl file.
Disk Space: 1000 MB Bandwidth: 10,000 MB Email Accounts: 25 Subdomains: 100 MySql DataBase: UNLIMITED This is test information for products
I want create multiple variables from this output to get below result so i can use like below 3 variables in tpl file.
$feature = Disk Space $value = 100 MB etc.. and also $feature.description = This is test information for products.
If this is an unclear question, let me know and I will attempt to clear it up.
Thanks
2
Answers
I’m sure this can be done cleaner but it’ll get the job done:
Output:
I just
echo
d out the pairs of key/value. You can store them into variables if you want of course.If you want the key/val pair stored in variables:
Output:
$keys
&$vals
are parallel arrays. This all is based on the format of five lines at the top of$description
withkey
:value
being the format.if the result string is same as in your question you can simply separate them by new line and then explode by
:
. here is code.Output: