-2

Question about php $variable[1]

What does it mean ?

$variable[1] 
$variable[2] 

I saw in some codes it array , what does it actually mean and present

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • Learn https://www.php.net/manual/en/language.types.array.php – Rahul Apr 30 '19 at 07:08
  • If `$variable` is an array, it gets or sets the value of the index with either 1 or 2. Can be used on strings as well, to pluck the letters of that position. Keep in mind, PHP is zero-indexed (starts at 0, not 1). – Qirel Apr 30 '19 at 07:08
  • 1
    in case variable is string or array, will give you this:- https://3v4l.org/O58h7 Or may be this:- https://3v4l.org/cm8FG – Alive to die - Anant Apr 30 '19 at 07:08

1 Answers1

1

it means that $variable is an array and you are calling the index (1/2).

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
TheBlueOne
  • 486
  • 5
  • 13
  • It does not automatically mean its an array. It can be used on strings, too! – Qirel Apr 30 '19 at 07:09
  • a string is an array of chars – TheBlueOne Apr 30 '19 at 07:13
  • Uhh, no, it isn't.. It's a combination of multiple characters, but it's not an array. That's a different type. – Qirel Apr 30 '19 at 07:14
  • its not just an array of chars but it has one and it gives direct acces to it [see this](https://www.php.net/manual/en/language.types.string.php#language.types.string.details) – TheBlueOne Apr 30 '19 at 07:16
  • A string and an array are two very different things. But, *in PHP*, you can access the specific characters of a string with using `$string[2]`, the same way you can access elements in an array. That does not make a string an array, they are still two different types. – Qirel Apr 30 '19 at 07:17