1 00:00:00,310 --> 00:00:05,120 We left our catalog page looking like this with the bulleted list of four items. 2 00:00:05,120 --> 00:00:05,750 In the code for 3 00:00:05,750 --> 00:00:10,930 the catalog.php file, we had our catalog stored in a simple indexed array. 4 00:00:10,930 --> 00:00:12,750 Instead of letting PHP assign the key, 5 00:00:12,750 --> 00:00:16,800 we have specified our own item ID for the key. 6 00:00:16,800 --> 00:00:20,640 Each element in the main catalog array represents one item. 7 00:00:20,640 --> 00:00:25,860 Right now each element has a piece of text with a title of the item as its value. 8 00:00:25,860 --> 00:00:30,150 Let's change this first element making the value another array 9 00:00:30,150 --> 00:00:31,310 instead of just a piece of text. 10 00:00:32,680 --> 00:00:33,930 Let's go back into our catalog. 11 00:00:35,480 --> 00:00:38,950 Before we add any more information to our array here, 12 00:00:38,950 --> 00:00:41,500 let's separate out this code into a new include file. 13 00:00:41,500 --> 00:00:46,720 We'll name this file data.php. 14 00:00:46,720 --> 00:00:51,770 Let's copy our array from catalog.php, 15 00:00:51,770 --> 00:00:55,284 and paste it into data.php. 16 00:00:55,284 --> 00:01:01,080 Add our opening php tag, and the closing php tag. 17 00:01:03,090 --> 00:01:05,910 Now we're ready to add a new dimension to our array. 18 00:01:05,910 --> 00:01:09,020 I'm going to show you another shortcut for adding an array. 19 00:01:09,020 --> 00:01:12,980 Instead of using the keyword array with parentheses, 20 00:01:12,980 --> 00:01:16,110 we can simply add open and closed square brackets. 21 00:01:16,110 --> 00:01:19,240 We'll use this as we add another array to the first element 22 00:01:19,240 --> 00:01:20,540 in our main catalog array. 23 00:01:22,020 --> 00:01:24,630 I'll refer to this as our interior array, 24 00:01:24,630 --> 00:01:27,840 because it's inside our main catalog array. 25 00:01:27,840 --> 00:01:32,370 This interior array will contain information about this one item. 26 00:01:32,370 --> 00:01:34,590 One element for each piece of information. 27 00:01:35,930 --> 00:01:37,680 The first element will contain the title. 28 00:01:38,910 --> 00:01:43,490 We'll specify the key for each element here using a piece of text to describe 29 00:01:43,490 --> 00:01:45,430 what information the element contains. 30 00:01:46,540 --> 00:01:53,140 Title and then the = sign, followed by the > sign. 31 00:01:53,140 --> 00:01:57,550 Then we also have the value in quotation marks, because it too, is a piece of text. 32 00:01:58,720 --> 00:02:01,500 We need to add another element to this interior array, for 33 00:02:01,500 --> 00:02:03,610 all the information about this item. 34 00:02:03,610 --> 00:02:05,900 We separate items in array with a comma. 35 00:02:07,220 --> 00:02:11,970 Then we can create a new element for each of the shared attributes of this item. 36 00:02:11,970 --> 00:02:15,368 The next element we'll add is the path to the image. 37 00:02:15,368 --> 00:02:21,802 Call it "img" =>, our path 38 00:02:21,802 --> 00:02:31,730 is img/media/design_patterns.jpg. 39 00:02:31,730 --> 00:02:33,010 Then we'll add the genre. 40 00:02:36,455 --> 00:02:39,389 Tech. 41 00:02:39,389 --> 00:02:40,702 The format. 42 00:02:43,656 --> 00:02:44,871 Paperback. 43 00:02:47,815 --> 00:02:48,770 And the year. 44 00:02:52,260 --> 00:02:56,070 Since this value is a number, it does not need quotation marks. 45 00:02:57,870 --> 00:02:59,640 Finally, let's specify the category. 46 00:03:02,420 --> 00:03:05,610 This will match up with one of the navigation headings, books, 47 00:03:05,610 --> 00:03:06,670 movies, or music. 48 00:03:07,860 --> 00:03:08,490 This one's Books. 49 00:03:10,560 --> 00:03:14,810 Each category will have some extra details that are specific to the item category. 50 00:03:14,810 --> 00:03:19,650 Design Patterns is a book, so now we need to add the extra book elements. 51 00:03:19,650 --> 00:03:21,651 To start with, we'll add ISBN. 52 00:03:25,811 --> 00:03:27,112 Then we'll add publisher. 53 00:03:31,177 --> 00:03:32,490 And finally, authors. 54 00:03:33,850 --> 00:03:36,720 Although many books only have one author, some books, 55 00:03:36,720 --> 00:03:39,350 including this one, have multiple authors. 56 00:03:39,350 --> 00:03:42,530 Instead of making authors a string like our elements, 57 00:03:42,530 --> 00:03:44,170 we'll make authors another array. 58 00:03:46,840 --> 00:03:50,450 And just like that, we have a third dimension to our associated array. 59 00:03:50,450 --> 00:03:51,614 Let's add our authors. 60 00:03:59,166 --> 00:04:01,770 And let's finish off our arrays. 61 00:04:01,770 --> 00:04:05,730 We've changed the first element in our main catalog array from a simple piece of 62 00:04:05,730 --> 00:04:10,150 text to a full associative array, this makes our item much more useful. 63 00:04:11,210 --> 00:04:14,570 We now have attributes for each item grouped together. 64 00:04:14,570 --> 00:04:17,060 This will allow us to display details of each item. 65 00:04:17,060 --> 00:04:19,780 To get our catalog ready to use, 66 00:04:19,780 --> 00:04:22,630 we'll need to add the details of each item in the array. 67 00:04:22,630 --> 00:04:27,160 For movies and music, we'll have elements specific to those items. 68 00:04:27,160 --> 00:04:30,860 You probably don't want to watch me type out all the code for all the other items 69 00:04:30,860 --> 00:04:34,490 in the catalog, and you probably don't want to type them yourself. 70 00:04:34,490 --> 00:04:38,220 So I've attached a text file to this video with the code you'll need. 71 00:04:38,220 --> 00:04:42,670 I also added a few more items so we have four items in each category. 72 00:04:42,670 --> 00:04:46,529 Download that text file and copy the code from that file and 73 00:04:46,529 --> 00:04:48,831 paste it into our data.php file. 74 00:04:52,447 --> 00:04:55,612 Also, when ending a php file with php code, 75 00:04:55,612 --> 00:04:59,510 you do not need to use the php closing tag. 76 00:04:59,510 --> 00:05:03,390 Leaving off the closing tag is a widely accepted coding practice 77 00:05:03,390 --> 00:05:06,260 used by projects such as WordPress and Drupal. 78 00:05:06,260 --> 00:05:10,410 In fact, the Zend Framework specifically forbids using it. 79 00:05:10,410 --> 00:05:16,540 The closing tag is not required by PHP, and by omitting it at the end of a file, 80 00:05:16,540 --> 00:05:20,120 you guarantee that no trailing whitespace can be added. 81 00:05:20,120 --> 00:05:22,970 These might cause unexpected results. 82 00:05:22,970 --> 00:05:26,447 Once you've pasted your code the full array should look like this.