gornycreative Posted July 25, 2021 Share Posted July 25, 2021 So I'm trying to wrap my head around what each() can do and when I need to use a regular foreach() structure. I have the following code: $pages->find('template=social-media-platform, !social_media_share_url=""')->each(function($zxc,$val){ $smi = ($val->social_media_alt_icon<>'') ? $val->social_media_alt_icon : $val->social_media_icon; $ary[$zxc] = array( "social_media_share_url" => $val->social_media_share_url, "social_media_share_parameters" => $val->social_media_share_parameters, "social_media_icon" => $smi ); return $ary[$zxc]; }) What I am trying to do is generate an array that is a subset of the values normally passed through the system, and trying to coalesce two value so that if the default value is empty and an alternative is not, the alternative is plugged into the same default value key. Regardless of whether I return $ary or $ary[$zxc] what I get back is a PageArray with page fields I have referred to in the loop included, but the substitution isn't made. I will do this with a regular foreach() but I guess I am trying to understand what the purposes/limitation of the keyed function argument are if you always get a PageArray as the result. What I'm trying to get is something simpler. Or I can actually use the PageArray object and just do the coalesce logic at output. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now