Houses for Sale | Loans | Credit Cards | Mortgages | Mortgage Calculator
PHP Array Question [Archive] - PCMech Forums

PDA

View Full Version : PHP Array Question


Battery Powered
02-05-2003, 07:53 AM
Hi

At the moment im using this to print part of an array

print (" $values[0] ");

which works fine, but the value in the '[ ]' i want to be dynamic,
what im trying to do is this

print (" $values[ $number * 7 + 1 ] ");

i want the value in the '[ ]' to be a variable multiplied by 7 and then having one added to it

ive tried and tried and cannot get it to work,
any ideas?

Thanks,
James

DrZaius
02-05-2003, 05:03 PM
Hi James,

Try calculating the index outside of the print statement, like this.

$index = $number * 7 + 1;
print($values[$index]);

Battery Powered
02-09-2003, 05:25 PM
Ok i managed it by doing the following if any one is intrested:




$values = file("data.dat");

for($i = 0; $i <= sizeof($values); $i=$i+7)
{
print ("$values[$i] ") ;
}



Not sure if any of you are intrested in this, but it gives me my gap of 7 : )

All the best,
James

aym
02-10-2003, 05:23 PM
Why converting to string? I think :

print ( $values[ $number * 7 + 1 ] );

Should work just fine.