This is as simple as it gets, but I can't see why I'm getting 0 when I echo $num[3]
from this PHP array.
$num=[00000004,00000002,00000005,00000009]; echo $num[3];
This is as simple as it gets, but I can't see why I'm getting 0 when I echo $num[3]
from this PHP array.
$num=[00000004,00000002,00000005,00000009]; echo $num[3];
Because of the leading zero's, it needs to be a string, not a number:
$num=['00000004','00000002','00000005','00000009']; echo $num[3];
Based on Integers Manual
To use octal notation, precede the number with a 0 (zero). To use hexadecimal notation precede the number with 0x. To use binary notation precede the number with 0b.
Your values are actually representing octal notation and that's why you are leading to issue.
Convert them to string:
$num=[
'00000004',
'00000002',
'00000005',
'00000009'
];
echo $num[3];
Output: https://3v4l.org/ktsJY
Note:- From Php7 onward it will give you Parse error: Invalid numeric literal
The data is not stored correct, they are stored as a number but they are strings so they need to be stored as a string. When I run your code it throws an error
Parse error: Invalid numeric literal in [...][...] on line 2
The code below wil return 00000009
$num=['00000004','00000002','00000005','00000009']; echo $num[3];
Your syntax is not correct,try this
$num = array("00000004","00000002","00000005","00000009");
echo $num['3'];