Array I thought it was a seven-headed bug, but it’s just simple powerful variables.
A normal variable can save my name, for example:
$nome = "Lucas";
If we give a echo
what will be shown is:
Lucas
Ja com array, that’s what I said, are "variables" only they keep more information.
For example, you can save my name and surname:
$nomeSobrenome = ["Lucas"];
$nomeSobrenome = ["Carvalho"];
As I wrote above, she created 2 spaces, that is, starting from 0, she created 0 and 1. Same thing if I had created two different variables. If I give a echo $nomeSobrenome[0] . " " . $nomeSobrenome[1]
, the point in the middle there, serves to concatenate, ie to add/integrate two information in the same command, without having to give a lot of echo, and the space I gave there, with the quotes, is to give space between the commands. It’ll show like this at the end:
Lucas Carvalho
Instead of integers in the indices of arrays, you can also query them by strings:
$pessoa = ["nome" => "Lucas de Carvalho Alves"];
If I give an echo $pessoa['nome'];
Will display Lucas de Carvalho Alves
This is because "name" received "Lucas de Carvalho Alves" by the sign of =>
(arrow) is kind of a sign only of equal =
, in this case, it is an entrustment signal.
There is not much secret, it is only create your own exercises, and go practicing.
The official manual is very good! http://php.net only has some bad things translated that it is nice to give a Google even.
– Lucas de Carvalho
But the manual only teaches how to use, it doesn’t offer exercise. That’s the problem :/
– Alex Dev
Make these http://professor.leonardomeirelles.com/wp/wp-content/uploads/2017/04/Lista-de-Exerc%C3%Adcios-Array1.pdf
– user60252