Basic PHP Tutorial 11: Arrays part 1, basic array

sentdex · Beginner ·🛠️ AI Tools & Apps ·13y ago

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 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

Related AI Lessons

Up next
Answering Revit Questions for Reddit
Balkan Architect
Watch →