-
-
Save loraxx753/3908087 to your computer and use it in GitHub Desktop.
<?php | |
//Starting values (one way to do an array) | |
$peopleWhoHateChris = array('Jacob'); | |
//Adding to the array | |
$peopleWhoHateChris[] = 'John'; | |
$peopleWhoHateChris[] = 'Mike'; | |
//Another way to add | |
array_push($peopleWhoHateChris, 'Luke'); | |
//Step 1: print out the number of people who hate Chris by saying "X people think Chris is a fucking asshole." | |
//Step 2: Print out the 3rd person who hates Chris (should be Mike) | |
//Step 3: Remove the last person from the array, then print out each person in a list (with a loop) | |
//You're gonna have to look stuff up. | |
//Try googling "remove last item from array php" |
Ok think this is what you wanted for all steps. Let me know if it is not please.
Hah oops. Just saw you wanted me to print out the people in a loop. Hmm. Let me look into that.
Ok this should be all you wanted for real this time. Only problem is - how do I get a space between the unset and the foreach to print out the names. It all jams into a line and I cant figure out how to insert a nbsp or /n correctly.
Almost right, you're unsetting "Mike" instead of the last item "Luke"
As for how to break it up, remember you can echo html right into this, so you could do print $name."
"; to add a line break between each or $name." "; for a space.
Damnit... lemme try that again
As for how to break it up, remember you can echo html right into this, so you could do print $name."<br/>"; to add a line break between each or $name." "; for a space.
Did this earlier, working on part 3 later or tomorrow. This does help. I didnt know how to do step 2 even though it was an easy method. Was trying to search_array and was wondering why it kept printing out an int like 2 instead of Mike, but I solved it with some work.