Basic PHP Tutorial 11: Arrays part 1, basic array
Key Takeaways
Creates a basic array in PHP
Full Transcript
what is up welcome to the 11th php tutorial i'm afraid i'm always going to say python anyway um building off a switch i forgot to mention one more thing you could have um multiple cases so you could say like case one like let's say we got rid of johnny and we could say case one and then you could have um a semicolon and then you could do case uh gianni like that so you could theoretically have um like multiple cases right there so let's save this so we save that pop on over and we'll refresh and you can see case one is called so you can you can like if you're gonna echo or usually what you're gonna do is you know perform some code so if you're gonna perform the same code whether it's case 1 or case johnny then you can just do this and save yourself some lines i just forgot to mention that so there it is now so now you really know everything there is to know about switches so now let's discuss something a little more fun and that's going to be arrays now an array is just like a it's a variable and it's got multiple elements saved to that variable and then what you can do is reference just one of the elements at a time or maybe like a span of those elements like the first 20 elements of that rare and so on and the arrays within php there's actually um three different types of arrays so i'm just going to do the first one here and then we'll do the next ones next but there is just like a typical what you would think of as an array where it's just like a one-dimensional it's just it's you define a variable and then you define a bunch of quote unquote i would say parts to that variable which can be referenced next though there are associative arrays where you define the array and then you define the parts of the array and then you define like a part of that part basically or you give a value to that part if you have any idea about uh python it's it's quite similar to a python dictionary where you have the you know defining of the dictionary will be the definition of the array then you've got you know part one which would be the key and then part two is the value and um they're even referred to as the same things within like keys and values in php so if you understand dictionaries you'll understand associative arrays and then finally you have the ability to have a multi-dimensional array so in theory you could almost make like a database out of a multi-dimensional array that's like it's like a spreadsheet practically um so anyway we'll get into each of those and really like the purposes of each of those but for now let's just do a typical already so we'll just say a typical array equals and to define an array you literally uh write out array and then you have a parenthesis and within the array you specify the things within the array so we'll just uh we're going to have four parts to this array and we'll just say oops part part one then we'll say part two part three and part four semicolon remember in those now uh to show you what you can do with um an array is if you call what happens when we call a typical already and spell it correctly save pop on over here refresh and we actually got oops sorry let's let's let's uh let's echo it say refresh and you see we get this like it just says array and so you kind of want to know like okay well what's in here so now we're going to run on back to uh print the print function and within the print function you have print r and this would be a time to use print r now print r is exactly that it's a function so within the function you put the what you want to apply that to so you'll put the actual variable in here now this is really more so you can like visualize as you code but it's still pretty useful um to print it out from time to time so anyway you can use print underscore r and when we refresh now you're presented with a more visually appealing one like it tells you the zero width element applies to one the first element two second element three and so yeah if you're not familiar with ordering within programming the first element is classified as zero the second element one and so on but it starts at zero not at one so that's your typical um your typical array and then what you can do with this later on is you can call specific parts like let's say you want to just oops echo and then you typical array and you want to just reference like one of the elements within here you can reference element zero or something like that and so we'll save this and we'll run this and we'll see what it spits out at us and it spits out part one because it spits out the zeroth element which is part one now uh in a pretty future video or pretty near future video um i'll be showing you kind of one of the main benefits to an array in my experience using arrays is most useful um to use an array with a for loop or rather if it's in php for each loop and you use you run through like for each element in this array do this and with an array you can actually um append remove whatever items from the array it's a mutable list but we'll get in more into that later on but for now this is just a typical array if you want to append something to this array it's really quite simple um you just define say like as you saw before we called it by typing typical array and then put something in the square brackets you can do this by going typical array and you see we have a zero one two three so we can say the fourth element in this array equals um well it only makes sense for us to say part five um and now let us let's print out the full one now so we'll say print r and we want to do this to typical array save that pop over here refresh as you can see it actually added that part to our array so that's how you'll add to arrays so that's a typical array as always thanks for watching thank you for your support your subscriptions and until next time
Original Description
Link to the full playlist:
http://www.youtube.com/playlist?list=PLQVvvaa0QuDcYpcjrNB43_iKqla5UeQw_
Sentdex.com
Facebook.com/sentdex
Twitter.com/sentdex
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 20 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
▶
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
🎓
Tutor Explanation
DeepCamp AI