Force array key start from 1
If you need an array that starts its key from 1 instead of default zero, this tip can be helpful:
$arr = array(1 => 'foo', 'bar', 'baz', 'meh');
var_dump($arr);
/*
output:
array(4) {
[1]=> string(3) "foo"
[2]=> string(3) "bar"
[3]=> string(3) "baz"
[4]=> string(3) "meh"
}
*/
Keys after the first are numbered automatically.
Written by Marco Cervellin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#