Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

3.1.10 ArrayList / foreach key => value / same value


Go to End


577 Views

Avatar
timo

Community Member, 47 Posts

17 April 2015 at 2:59am

Hi!

Maybe more of a kind php - question but i hope someone can help me anyway.
In my function i return an array, i can loop and thats working.
That gives me:

Layout: John
Strategy: John
Management: Martin

so if the same person has more than one 'jobs' (like John)
how can i get:

Layout and Strategy: John // or Layout, Strategy and someOtherJob: John // semiclone + 'and' before last
Management: Martin

//$InfoFieldArray = array('Layout' => 'John', 'Strategy' => 'John', 'Management' => 'Martin');
	
	public function createInfoFields($InfoFieldArray){ 
		
		$Info = ArrayList::create();
		foreach($InfoFieldArray as $key => $value ){
			$fields = new ArrayData(array('FieldName' => $key, 'Value' => $value));
			$Info->push($fields);
		} 	
		return $Info;
	}

Hope you can help.
thanks.timo