Jump to content
Larry Ullman's Book Forums

OkComputer

Members
  • Content Count

    11
  • Joined

  • Last visited

Community Reputation

0 Neutral

About OkComputer

  • Rank
    Newbie
  1. Hugo, the value of the input field for the terms is already preset in the html markup, you're really validating that the check box was checked.
  2. Thanx for the assistance. I've modified the code accordingly, and here's what I got now: $flag = true; $words_Array = explode (' ', $_POST['words']); $count1 = count($words_Array); if ($count1 < 5) { echo "<p>Please enter at least 5 words.</p>"; $flag = false; } foreach ($words_Array as $word) { if (is_numeric($word)) { echo "<p>Please do not enter any numbers.</p>"; $flag = false; } elseif (empty($word)) { echo "<p>You have entered an empty space as a word. Please enter at least 5 words.</p>"; $flag = false; }
  3. Hi. First off, this is in regards to exercise dealing with using a foreach loop instead of implode(). I was having trouble with it, and of course looked up what was posted here already, but I want to do more. By the I mean I wanted to validate that the form data was not empty, had no numbers, and had a minimum of five words that will of course be alphabetized(though I'd rather being doing some analysis with it for simple patterns like the avg number of characters by word, number of vowels, number of constants, but let me just be simple about it for now). Here's the code(just a note, to gi
  4. I think i got it. You use the foreach loop to label/organize the nested arrays stored in the multidimensional array, in this case, $music, and then you pull out the info you want accordingly with the loop + formatting. The understanding being that you want the index names of the first two nested arrays, that store the genre name and artist name, repectively, and the value of the last array that stores the album titles for each artist. Do I have it right ?
  5. Just woke up. This is the first thing I loooked at after brushing my teeth. Thanx a lot. I'm going to look over the code to understand how and why it works because I'm more of the why something works type of guy you know. But again, thanx a lot.
  6. Maybe, I'm not formatting it right, could that be the case or I'm I just totally off base here ?
  7. Just can't seem to get my head around the strucure for the foreach loop. Getting various results, no avail as nothing's lining up. This is how I have it now, and I'm just too tired to think straight at this point. $music = array ( 'Jazz' => $jazz, 'Classic Rock' => $classic_rock, 'Alternativ Rock' => $alternative_rock, 'Indie Rock' => $indie_rock, ); foreach ($music as $a => $ { echo "Genre $a:<br />"; foreach ($b as $key => $value){ echo "<pre>" . print_r($key) . " : " . print_r($value) . "</pr
  8. Thanx, I just made myself a cup of coffee and started googling through stackoverflow posts, the php manual, etc.. and you're right! So changed my codes for the three genres arrays to: $jazz = array ( 'Miles Davis' => array ('Kind of Blue', 'Bitches Brew', 'Sketches of Spain', 'Birth of the Cool'), 'John Coltrane' => array ('A Love Supreme', 'Blue Train', 'Giant Steps', 'My Favorite Things'), 'Dave Brubeck' => array ('Time Out', 'Time Further Out', 'Times Changes', 'Indian Summer'), ); $classic_rock = array ( 'The Beatles' => array ('Abbey Ro
  9. Hello, everyone. I created a multidimensional array that consists of 4 music genres in which each genre has 3 artists(using strings as keys) who in turn have 4 albums each(string values), but when I iterate over the multidimensioal array with a foreach loop, only the first album(the 1st string value) is associated with the artist(the string key). My intention was to map multiple string values to each string key/index, and have an output as such. Artist: Miles Davis Albums: Kind of Blue, Bitches Brew, Sketches of Spain, Birth of the Cool. Here's the code: <?php $jaz
  10. Hi, I was having similar issues with this as well, till of course I realised my error and what Larry was referring to. Anyhow, here's my code(Btw, all the code beforehand is the same as in the book including html info and opening and closing php tags): Code: foreach ($books as $key => $value) { echo "<pre>", print "<p>" . print_r($key) . ":" . print_r($value) . "</p>\n"; "</pre>"; } ------------------------------------------------------------------------------------------- Same as above, just shortened
×
×
  • Create New...