Home › Forums › Add-ons › Repeater Field › Problem with an array
Hi,
I’m using ACFs Repeater field to make an array. The array should look like this:
array (size=3)
‘2020-06-06’ =>
array (size=2)
‘title’ => string ‘Pyöräily’ (length=10)
‘description’ => string ’45min spinning, täysillä’ (length=26)
‘2020-06-17’ => =>
array (size=2)
‘title’ => string ‘Jalkapallo’ (length=10)
‘description’ => string ‘Koko halli varattu’ (length=18)
‘2020-06-22’ => =>
array (size=2)
‘title’ => string ‘Sulkapallo’ (length=10)
‘description’ => string ‘Koko halli varattu’ (length=18)
But now it looks like this:
array (size=3)
0 =>
array (size=2)
‘title’ => string ‘Pyöräily’ (length=10)
‘description’ => string ’45min spinning, täysillä’ (length=26)
1 =>
array (size=2)
‘title’ => string ‘Jalkapallo’ (length=10)
‘description’ => string ‘Koko halli varattu’ (length=18)
2 =>
array (size=2)
‘title’ => string ‘Sulkapallo’ (length=10)
‘description’ => string ‘Koko halli varattu’ (length=18)
How I should fix my code so that those numbers would be replaced with dates?

Hmm, I guess there are two solutions to this. The first would be to create a nested repeater, i. e. one repeater for the event dates, and inside that, another repeater for event title and description. And then you loop over the dates, and in each iteration, you loop over the nested repeater to retrieve the other two field values. The documentation describes such a scenario in the section titled “Nested loops”.
The other option would be to create an associative array, but for that, you can’t use array_push(), you need to use the square bracket notation with the date string as key, like so:
$events[$event_day] = $single_event;
The topic ‘Problem with an array’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.