When I first started working with foreach loops, this particular syntax seemed mysterious to me, too, and it wasn’t until I needed it that its usefulness became obvious. Works that way for a lot of “things you see in code.”
Anyway, to answer the question, in the sample code, using as $key => $value
makes the key ($slug
) available as a variable in the ensuing code block. The $page_definitions
array has two top-level keys, 'member-login'
and 'member-account'
which (after an already-exists? check) become the slugs for two new pages that the function creates (inserts) with the values of the two-member ('title'
and 'content'
) arrays or sub-arrays as the new pages’ title and content: one entitled “Sign In” with content the shortcode [custom-login-form]
, and one entitled “Your Account” with [account-info]
shortcode.
So, if I were on that site, after the function ran, I’d find two pages, one with a slug of siteurl/member-login, entitled Sign In, showing a custom login form, etc., and a second page with a slug siteurl/member-account, with content created by the account-info shortcode. The two shortcodes probably produce differentiated content based on logged-in status and identity of the user.
Got it? [EDITED AND FIXED after I screwed up the answer the first time!]