User Tools

Site Tools


en:web_development:media:named_arrays

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:web_development:media:named_arrays [2021/12/25 14:40]
mag
en:web_development:media:named_arrays [2023/08/16 09:33] (current)
Line 1: Line 1:
-====== Web Development Lesson - Media ======+====== Web Development Lesson - Media ======
 ===== Named Arrays ===== ===== Named Arrays =====
 ==== Objective ==== ==== Objective ====
Line 181: Line 181:
     $animals['item3'] = 'rabbit';</code>     $animals['item3'] = 'rabbit';</code>
   * We can read the array in the same way. Add this code to the <html><main></html> tag.   * We can read the array in the same way. Add this code to the <html><main></html> tag.
-<code>    echo "MURRAY: the first photo is $photos['Photo 1'].";</code>+<code>    echo "MURRAY: the first photo is {$photos['Photo 1']}.";</code>
   * Now view the page and check the results.   * Now view the page and check the results.
  
Line 204: Line 204:
 <?php <?php
     }     }
-?>+?></code>
   * There are a couple of things to note here.   * There are a couple of things to note here.
-  * We've used a couple of new HTML tags. <html><figure></html> is a block element that can be used to present an image and a caption. <html><figcaption</html> is used to hold the caption for an image.+  * We've used a couple of new HTML tags. <html><figure></html> is a block element that can be used to present an image and a caption. <html><figcaption></html> is used to hold the caption for an image.
   * Secondly, we've changed the way we encode the HTML block. Rather than include all the HTML inside a string, which requires us to add <html>\t</html> and <html>\n</html> to make it readable in the View Page Source view, we've left the HTML as is and created a new PHP block for each variable to be displayed.   * Secondly, we've changed the way we encode the HTML block. Rather than include all the HTML inside a string, which requires us to add <html>\t</html> and <html>\n</html> to make it readable in the View Page Source view, we've left the HTML as is and created a new PHP block for each variable to be displayed.
   * This is much more readable for me.   * This is much more readable for me.
   * Refresh your page and check that it works as it should.   * Refresh your page and check that it works as it should.
 +  * It needs a bit of styling. Try this or add your own.
 +<code>figcaption {
 +  display: block;
 +  text-align: center;
 +  font-family: 'Arial', sans-serif;
 +  color: green;
 +}</code>
  
 ==== While Loop ==== ==== While Loop ====
Line 228: Line 235:
   * So this is another way of running the same code multiple times.   * So this is another way of running the same code multiple times.
  
-[[en:web_development:databases:tables|Next: Tables]]+[[en:web_development:media:exercises|Next: Exercises]]
en/web_development/media/named_arrays.1640472040.txt.gz · Last modified: 2023/08/16 09:33 (external edit)