Jump to content

Is there anyway to make an array not start at "0"?


Lucky2710

Recommended Posts

<?php
for($i = 1; $i < 10; $i++) {
$flip[$i] = 'Yes';
}


echo '<pre>'; print_r($flip); echo '</pre>';

?>

 

Outputs

Array
(
    [1] => Yes
    [2] => Yes
    [3] => Yes
    [4] => Yes
    [5] => Yes
    [6] => Yes
    [7] => Yes
    [8] => Yes
    [9] => Yes
)

You could use array_unshift to prepend a useless item to the front of the array. I wouldn't recommend it though. The reason 0 was chosen for the start of array indexes is because it's typically more useful and less confusing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.