Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing variables in arrays

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
If i had an array

array = (red,yellow,blue)

With the array values separated by commas

How would I access say the value blue , Say to do a Conditional

Ex.
if ($array[2]==blue)
echo color is blue

I used this, But It gives me script out of range
 
The array values must be separated by spaces.
Add the line
Code:
set array = ( `echo $array | tr ',' ' '` )
after the first initialization of array to recreate the variable value whith all ',' (commas) translated to ' ' (spaces).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top