Jump to content

fintanstrasbourg

Members
  • Content count

    4
  • Joined

  • Last visited

Community Reputation

0 Neutral

About fintanstrasbourg

  • Rank
    Newbie
  1. Associative Array

    Thanks very much for the help Foxy Mod it's greatly appreciated indeed...
  2. Associative Array

    Hi there, Been trying to learn PHP in my spare time the last few weeks. Setting myself little tasks, challenges, mini projects etc. but I'm quite stuck on this one. I'm trying to create an associative array to hold the following information on monthly rainfall in millimetres (jpeg of table attached below). I then want to find the minimum, maximum and average rainfall per month and per year. I've created two arrays experimenting but only the second one is associative (I've attached the php file below as well), but here is the code anyways... <?php $multidimensional_array = array(array("Jan", 292.9, 147.1, 175.9, 130.6, 107.7), array("Feb", 53.7, 154.9, 195.1, 91.1, 144.6), array("Mar", 92.8, 72.3, 87.2, 106.8, 64.4), array("Apr", 64.2, 55.4, 38.3, 63.6, 42.0), array("May", 135.3, 128.6, 90.4, 111.2, 45.4), array("June", 37.1, 63.4, 40.5, 27.2, 68.0), array("July", 76.5, 31.6, 35.8, 82.7, 66.9), array("Aug", 97.1, 153.8, 90.0, 93.4, 107.4), array("Sep", 39.2, 16.1, 72.4, 87.9, 88.5), array("Oct", 57.6, 125.2, 105.2, 49.7, 35.3), array("Nov", 184.4, 154.4, 129.3, 190.5, 69.2), array("Dec", 274.3, 100.7, 110.2, 233.2, 74.0), ); $multidimensionalAss_array = array( array("month"=>"Jan", "2012"=>92.9, "2013"=>147.1, "2014"=>175.9, "2015"=>130.6, "2016"=>107.7), array("month"=>"Feb", "2012"=>53.7, "2013"=>154.9, "2014"=>195.1, "2015"=>91.1, "2016"=>144.6), array("month"=>"Mar", "2012"=>92.8, "2013"=>72.3, "2014"=>87.2, "2015"=>106.8, "2016"=>64.4), array("month"=>"Apr", "2012"=>64.2, "2013"=>55.4, "2014"=>38.3, "2015"=>63.6, "2016"=>42.0), array("month"=>"May", "2012"=>135.3, "2013"=>128.6, "2014"=>90.4, "2015"=>111.2, "2016"=>45.4), array("month"=>"June", "2012"=>37.1, "2013"=>63.4, "2014"=>40.5, "2015"=>27.2, "2016"=>68.0), array("month"=>"July", "2012"=>76.5, "2013"=>31.6, "2014"=>35.8, "2015"=>82.7, "2016"=>66.9), array("month"=>"Aug", "2012"=>97.1, "2013"=>153.8, "2014"=>90.0, "2015"=>93.4, "2016"=>107.4), array("month"=>"Sep", "2012"=>39.2, "2013"=>16.1, "2014"=>72.4, "2015"=>87.9, "2016"=>88.5), array("month"=>"Oct", "2012"=>57.6, "2013"=>125.2, "2014"=>105.2, "2015"=>49.7, "2016"=>35.3), array("month"=>"Nov", "2012"=>184.4, "2013"=>154.4, "2014"=>129.3, "2015"=>190.5, "2016"=>69.2), array("month"=>"Dec", "2012"=>274.3, "2013"=>100.7, "2014"=>110.2, "2015"=>233.2, "2016"=>74.0), ); //print_r($multidimensional_array); print_r($multidimensionalAss_array); ?> Could anyone give me some advice on where I'd go next with the associative array? I'm fairly sure I can't loop through it no? I'm fairly stuck on this and it's annoying me quiet a bit! Finding JavaScript easier to learn for sure... haha Thanks, Fintan table challenge.php
  3. Hi guys, thank you both very much for the help and advice on how to go about solving the problem, it's helped me a lot! Much appreciated indeed
  4. Hi there, I've recently started to try and learn JavaScript on my own in my spare time, as it's an area of work I'd like to get into (not exactly loving my current occupation). I'm trying to learn it from a book I got and finding it very difficult! Much harder than html and css (which I've been learning for a few months as well). I'm trying to answer this question below with a 'for loop' (which is partially running), but I'm really lost as to how to answer it using a function?? Could anyone give me some advice, as it's really doing my head in! It'd be greatly appreciated indeed.... Question: " Write a function that takes a character and returns false if it is not a vowel and true if it is. This function should be used in a program to count the number of non-vowels (not just consonants) and the number of vowels in a string that the user is asked to input. E.g. JavaScript Rocks! Number of vowels: 4 Number of non-vowels: 13 " Here is my attempt so far..... <html> <body><title>Function</title></head> <body> <h1>Function</h1> <script> var sent = (prompt("Please write a short sentence of your choosing")); var vowels = 0; var nonevowels = 0; for (i=0;i<sent.length; i++) { if(sent == "a" || sent == "e" || sent == "i" || sent == "o" || sent == "u") { vowels++; } if(sent == "A" || sent == "E" || sent == "I" || sent == "O" || sent == "U") { vowels++; } else { nonevowels++; } } document.write("Numberowels = " + vowels + "\n"); document.write("Numberone vowels = " + nonevowels); </script> </body> </html>
×