# What does  => 0 mean in this array?

I know this should be a pretty simple question, but I haven't been able to stumble upon an answer yet.

I have the following array

``````\$qid=1;
\$qid=2;
\$qid=3;
\$qid=4;
```

```

When I use print_r (\$ qid) I get the following

``````Array (
 => Array (  => 1  => 0 )
 => Array (  => 2 )
 => Array (  => 3 )
 => Array (  => 4 )
)
```

```

I don't understand  => 0

in

` => Array (  => 1  => 0 )`

If anyone can explain what  => 0 means in this array, I would really appreciate it. Thank.

EDIT: It turns out my array was really different from what I wrote above, because it was changed later in the code. Thanks everyone for the great answers. I am still reading them all and trying to understand them (arrays jelly my mind).

+3

source to share

7 replies

` => 0`

denotes an array element with a value `0`

.

The number in `[]`

is the keys of the array. So ``

- this is the second element of the numerically indexed array (which starts with ``

), and the value of the second element ( ``

) is `0`

.

PHP uses `=>`

both an operator to bind array keys / indices to their values.

### So a general explanation of this structure:

``````Array (
 => Array (  => 1  => 0 )
 => Array (  => 2 )
 => Array (  => 3 )
 => Array (  => 4 )
)
```

```

The outer array is a numeric index array, and each of its elements is a submatrix. The first one ( ``

) is an array containing 2 elements, and the rest ( ` through `

) are arrays containing only one single element.

+4

source

This two dimensional array is actually a one dimensional array of arrays, so you end up with nesting. A bit `[x] => y`

simply means that the index of the `x`

array matters `y`

.

Now your output in this case doesn't actually match your code, since

``````\$qid=1;
\$qid=2;
\$qid=3;
\$qid=4;
print_r(\$qid);
```

```

gives:

``````Array (
 => Array (  => 1 )
 => Array (  => 2 )
 => Array (  => 3 )
 => Array (  => 4 )
)
```

```

If you want to get:

``````Array (
 => Array (  => 1  => 0 )
 => Array (  => 2 )
 => Array (  => 3 )
 => Array (  => 4 )
)
```

```

(with the first array having two elements) you really need:

``````\$qid=1;
\$qid=0;

\$qid=2;

\$qid=3;

\$qid=4;

print_r(\$qid);
```

```
+3

source

You've probably added the second item to \$ qid  somewhere (\$ qid   = 0). This code

``````\$qid=1;
\$qid=2;
\$qid=3;
\$qid=4;
```

```

outputs the correct values ​​for me (without  => 0:

``````Array (  => Array (  => 1 )  => Array (  => 2 )  => Array (  => 3 )  => Array (  => 4 ) )
```

```
+2

source

This means that your index 0 in the original array contains another array of 2 elements.
In particular, it ` => 0`

means that the second element of the "child" array contains number 0.

+1

source

`````` => 0
```

```

in this simple way, you can say that 1 is your array and 0 is the value for key 1 0 is stored in 1 key of the array

thank

+1

source

Simply put, you have a numeric indexed multidimensional array. http://php.net/manual/en/language.types.array.php should have all the information you need to read.

As for why you have ` => 0`

, you need to dig a little deeper into your code to find out where it is assigned.

+1

source

I got the following result after printing the array using print_r:

``````Array
(
 => Array
(
 => 1
)

 => Array
(
 => 2
)

 => Array
(
 => 3
)

 => Array
(
 => 4
)

)
```

```

I think you could set a value for \$ gid   somewhere in your code.

+1

source

All Articles