Welcome Guest, Not a member yet? Register   Sign In
range & assoc arrays
#1

[eluser]carllawl[/eluser]
Im trying to make a register form with a dob set.
Ive done the day and month in an assoc array which took long enough, is there a way of making an assoc array for the year field without having to type it all out?

if it was a normal array you could do something like:

$year = range( 1910 , date("Y") ); // SET YEAR RANGE
$year = array_reverse( $year ); // PUT YEAR RANGE INTO VAR AND REVERSE IT

but im sure this isnt possible for assoc arrays?

Carl
#2

[eluser]WanWizard[/eluser]
Code:
$year = array_reverse( $year, TRUE );
will reverse the array while preserving the keys.
#3

[eluser]carllawl[/eluser]
yeah but im talking about assoc arrays so i can put it in a dropdown:

echo form_dropdown('year',$years);

but i dont want to type out 90 odd years and it would be handy if it could set the last value to the current year like in a range but the range doesnt support assoc arrays in pretty sure
#4

[eluser]WanWizard[/eluser]
Assuming you want an array like
Code:
$year[1990] = 1990;

You can do:
Code:
$year = range(date('Y'), 1910);
$year = array_combine($year, $year);
#5

[eluser]carllawl[/eluser]
thats the one! thanks for the help wanwizard




Theme © iAndrew 2016 - Forum software by © MyBB