I am currently studying PHP and not just how to cut and paste and hack someones code. I have this block of code I want to understand fully.
It's from a WordPress theme I'm using to help me learn PHP.
What I don't understand is the foreach loop. Here is what it looks like to my brain. I've included my analysis in comments above each line.
I'd greatly appreciate an analysis of my breakdown and explanation of the sybmols -> and =>.Code://I understand that $categories_list is a user defined function and is assigned the values that the wordpress function get_categories and it's arguments retrieve. $categories_list = get_categories('hide_empty=0&orderby=name'); //I also understand that $getcat is a user defined function that is assigned as an array that will be populated with what the foreach loop does. $getcat = array(); //For each value in the $categories_list as(I see the "as" being an assignment similar to =) $category. In effect assigning a variable to a variable that has not yet been defined or a temporary variable. foreach($categories_list as $category) { //Populate the $getcat array with the temporary variable $category using Wordpress parameters cat_id and cat_name. I don't understand the use of the -> symbols in this line and other places use the => symbol. $getcat[$category->cat_ID] = $category->cat_name; } //create a variable $category_dropdown and using the WordPress function array_unshift populate the drop-down with $getcat values with "Choose a category:" at the top. $category_dropdown = array_unshift($getcat, "Choose a category:");
Thank you in advance






Bookmarks