Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 02-05-2003, 06:53 AM   #1
Member (9 bit)
 
Join Date: Jan 2002
Location: UK
Posts: 389
PHP Array Question

Hi

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

PHP Code:
print (" $values[0] "); 
which works fine, but the value in the '[ ]' i want to be dynamic,
what im trying to do is this

PHP Code:
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
Battery Powered is offline   Reply With Quote
Old 02-05-2003, 04:03 PM   #2
Member (13 bit)
 
DrZaius's Avatar
 
Join Date: Jul 2000
Location: Fullerton, CA
Posts: 7,030
Hi James,

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

PHP Code:
$index $number 1;
print(
$values[$index]); 
DrZaius is offline   Reply With Quote
Old 02-09-2003, 04:25 PM   #3
Member (9 bit)
 
Join Date: Jan 2002
Location: UK
Posts: 389
Ok i managed it by doing the following if any one is intrested:


PHP Code:

$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
Battery Powered is offline   Reply With Quote
Old 02-10-2003, 04:23 PM   #4
aym
Registered User
 
aym's Avatar
 
Join Date: Nov 2001
Posts: 1,965
Why converting to string? I think :
PHP Code:
print ( $values$number ] ); 
Should work just fine.
aym is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:29 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2