PHP Array Map & Join in Wolf CMS

I'm attempting to add a set of data to a div's data attribute like so:

<div data-foo="<?php echo join(",", array_map(function($video){return $video->title();}, $videos)); ?>"></div>

But it fails at this line. However I have been able to verify that the array of videos do have titles. For example, this works:

<?php echo current($videos)->title(); ?>

I verified with an online PHP validator that there isn't a syntax issue, but I'm new to both PHP and Wolf CMS, so I'm not certain where it's failing or even how to properly debug it.

The desired output would be:

<div data-foo="84726530,84726614,84726779,84726915"></div>

Answers


Turns out it didn't like the anonymous function. Changing it to a named method fixed it.

<?php function callback($video){return $video->title();} ?>

<div data-foo="<?php echo join(",", array_map("callback", $videos)); ?>"></div>

Is this a version of PHP issue? Or does Wolf CMS limit things somehow? I have no idea, but at least it's working now.


Need Your Help

Running same JQuery function on many elements with same id

javascript jquery

I'm sure this is going to be simple well i hope it is. After racking my brain for days I have finally sorted my last problem thanks you someone on here, But now I have a new problem. I am dynamically

int() argument must be a string or a number, not 'SimpleLazyObject'

python django

I'm developing a web application via Aliexpress API.