Ad
PHP - Make PHP Function Output Multiple Instances
I have $tutorial->difficulty
which sometimes has multiple outputs, and for each output that goes into the breakCommas
function, I need to output a link for each one. Currently with how I have it, when $tutorial->difficulty
outputs multiple items, it basically clumps them all into a single link. From what I've read I realize you can't have multiple outputs per function. Any ideas how I can separate it to where it outputs multiple links?
PHP
function breakCommas($str) {
return ('<a href="'.str_replace(' ','-',strtolower($str)).'-tutorial">'.$str.'</a>');
}
HTML
<div>
<?=breakCommas($tutorial->difficulty)?>
</div>
Ad
Answer
try this function:
function breakCommas($str) {
$s = explode (",", $str);
$a = array();
foreach ($s as $st) {
$a[] = "<a href=\"".str_replace(" ","-",strtolower($st))."-tutorial\">{$st}</a>";
}
return implode("", $a);
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad