To retrieve the values within an array we must indicate the index or key using square brackets. Which means that if we want to get the value "Ford" from the previous array we must indicate an index of 1. Having specified only the values but not the keys coupled to them PHP automatically indexes each value with an increasing number starting from 0, $automobile = array('Mercedes', 'Ford', 'Alfa') Įven if you used different syntax the two arrays just created above are exactly the same. With short syntax and long syntax $automobile = In PHP 7 it is possible to declare arrays in two different ways, PHP provides about eighty functions that have the most disparate uses, so before creating operations on arrays on your own you should look for something ready to use. There are three different types of arrays, they are indexed, associative, and multi-purpose. PHP basics for expert web developers (1' part)Ĭomposite variable in PHP (Arrays, Object and more)Īlso this blog post is divided in 4 main sectionsĪrrays are ordered maps that associate values with keys, Simply read, find out that certain features or techniques exist and return to these pages when you feel ready for the next level. You do not have to learn all that is written here by heart! In this series, you are going to learn the basics of PHP but you will also see many small tips and features that you will only find in books and advanced tutorials.ĭepending on your level you may simply want to read them sporadically or skip them altogether. This blog post is part of a series called "PHP Basics for Expert Developers". In this episode, you will learn how to exploit these composite variables and create better programs with less stress and more fun. Think now about all the information in your ID card,Īll information types vary from strings to integers to floats that affect a unique object (in this case an individual or person). It will not be very performing, not to mention the difficulty in managing 20 different string variables, much more simple will be to create a single variable, an array in this case, and insert all 20 names inside. Think about the list of the names of your classmates, say that you had (or still have) 20 of them. This is useful when we want to group and work on many elements of the same type, In order to complete the variable section, you will now see two other types of variables that are Resources and Nulls.Īs you saw a composite variable is nothing but a set of scalar variables, There are two types of variables that belong to this group and are: Arrays and Objects, This type of variable is nothing more than a set of scalar variables combined into a single group. This type of variables is a bit more complex to grasp, but after understanding the concept you will not have any problems to fully exploiting their power in your scripts. Now it's time to introduce the variables of a composite type. They are the basics of any programming language. In the previous episodes of this series, you learned what the scalar variables are.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |