You can’t have code directly in the class definition. If you want it on instantiation, put it in the __construct function.
Also, be aware that you were missing a semicolon and .= is used to append to strings, not to add to arrays. I’ve fixed those as well:
<?php
class myclass {
private $arr = array(
'emails' => array(
'[email protected]',
'[email protected]',
'[email protected]'
)
);
protected $emails = array();
function __construct() {
foreach($this->arr['emails'] as $email) {
$emails[] = $email;
}
}
}
Related Posts:
- post__in – Placing content from a foreach loop inside of an array
- Load comments per post on click with AJAX
- Redirect Loop to Page, Can’t Find Origin, Can’t Remove [closed]
- trouble calling an import class from an action in a plugin before wp_cron executes
- Problem with displaying HTML content after in_array [closed]
- Array ids post to function have_post
- Can’t access PHP array inside script localization from javascript
- Output meta into arrays
- Trying to get property of non-object in shortocde
- How can I access specific posts brought back by query_posts?
- How to create a multidimensional array with multiple loops
- How to get user ID’s from multiple usernames?
- CPT while loop not working
- display post tags on single.php inside loop
- Exclude posts based on an array
- Add 2 values to post__not_in
- Adding a second loop breaks everything
- Query posts and display all dates in repeater field in chronological order
- Can’t print out returned value
- This webpage has a redirect loop issue with SSL page
- WordPress loop: Display if posts exist
- strange parse error when including a loop template within another template
- How can I access ‘key’ and ‘value’ from an array in a for loop?
- How to get files from loop for zip
- Redirect loop when trying to login to /wp-admin/ [duplicate]
- Display all authors and their only one latest post
- Remove comma from last item output from loop
- array of objects to do_action, callback gets singular object?
- Page template not displaying
- Can I use both a custom excerpt and a trimmed excerpt?
- How to get_template_part using AJAX?
- How can I modify the loop from a plugin without wiping out other filters?
- I’ve been out of the loop since 2.8. What did I miss?
- Loop first six posts in carousel, next eight in grid
- One custom loop with condition to check child posts
- Loop get_theme_mod
- Move sticky posts down in main loop
- Why only one post (and no pagination) on this variation of the loop?
- Loop in Related Posts WordPress
- Conditional query that displays on Woo product attribute pages
- Template structure
- Custom Loop Using Shortcode in Custom Page Template
- Listing subpages title and content and styling the first iteration differently
- Latest Post Styled Different Than other Posts
- ACF custom field in [closed]
- Split wordpress loop to multiple layouts
- Website Warning: call_user_func_array() expects parameter 1 to be a valid callback, class ‘Wppr_Public’ does not have a method ‘amp_support’
- Woocommerce: How to display product price [closed]
- Update status of all posts in a category
- is_active-sidebar loop
- Add “showing posts x to x of y” in custom post type paginated loop
- Custom Post Type on Homepage – Studiopress Genesis Framework
- New loop vs widget
- Obtaining values from objects
- Display a single category in blog section
- Query Nopaging action not having effect
- issue with if/elseif in_array inside foreach loop display only one post
- Yoast taking over my WordPress title tag [closed]
- Pagination broken after using 2 loops to show content
- Only show first image in foreach loop
- get_template_part() Not Working in Loop
- Querying another post category to match current post and display in loop
- Query posts only with actual text content (not including shortcode or images)
- Problem with Front-Page.php loading recent posts
- Where to add offset?
- How to synchronize The Loop with the max post per page?
- How to add a byline to all the pages?
- How do i create a list-posts-page?
- Displaying member join date on page
- Ascending order has strange effects on wordpress loop
- List ALL posts by author on author archive
- get post images to link to external sources
- Using is_page_template inside loop
- ACF – Get ID of relationship field in flexible content
- How to show the last article in a different way in my blog?
- Can’t limit posts_per_page in loop
- Slug is changing when I use WP_Query in a metabox of a post
- Check to see if a field is within an array in twig
- Custom loop not working in singular.php, working in other pages
- Strange problem with wp_get_attachment_image_src database (db) query count
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Archive sorted by month – separate
- Making a specific page wordpress compatable that is not index
- Humanmade | Custom meta box class: How to display a repeatable meta box group?
- change the_content images for different sizes (Desktop, tablet, mobile)?
- Get query result before posts are displayed?
- WordPress Group By Problem
- Home page loop with pagination problem
- WooCommerce custom loop pagination on front page
- Eliminate duplicates in a foreach loop [closed]
- Tag custom loop show posts
- While loop inside another while loop
- Problem with ms-thumb-frame-selected class in Master Slider
- I want the first post on my home page to be lengthier than the rest (example included)
- Loop with Custom Post Type Taxonomies and Interstitial Code
- Question about custom plugin
- loop mix my child-category and parent-category
- How can you make it so the comment box shows on some pages or posts but not all?
- Insert multiple custom components after x-number of posts