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
- Jquery Slider for profile template
- Retrieve each widget separately from a sidebar
- Should I use loop in the single.php file?
- wp_list_categories: get latest featured_image of category
- Where should I use post_class()?
- get_the_foo() in the loop – does it perform another query?
- Exclude filter on front page
- category__not_in — anyway to use category name instead of id?
- Check if date of post is yesterday
- Exclude first 2 posts with meta_key from loop
- Fix inefficient loop breaks post.php on form submit
- Make a custom loop inside single.php with pagination
- Why do I get `Call to a member function have_posts() on a non-object `? [closed]
- the_content() seems to block my ACF-code
- Pulling current post/page data into header.php
- Loop and Page template : my WP_query don’t take args
- How to split a loop into two columns
- Category Ajax call
- Transient loop issue
- popular post weekly and monthly
- WordPress Loop inside Loop?
- Get single post from tags array
- Apply an Incremental Counter in an Array Function
- Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?
- 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
- Loop counter style
- Can I add generic numbering HTML classes to items as a loop runs?
- 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
- Display a single category in blog section
- Query Nopaging action not having effect
- Yoast taking over my WordPress title tag [closed]
- Pagination broken after using 2 loops to show content
- Only show first image in foreach 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?
- Is file_exists() compatible with timthumb.php? [closed]
- List ALL posts by author on author archive
- Using is_page_template inside loop
- ACF – Get ID of relationship field in flexible content
- Staggering featured post using ‘sticky’
- 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
- How to fix pagination for custom loops?
- 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
- 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
- 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?
- Divide loop into several columns based on post custom field and enable infinite scrolling
- Query Loop Block: possible to restrict just child pages?