Exercise: Parallel arrays
Parallel Arrays: Two or more arrays with corresponding components having
related information. For example:
$names = array();
$costs = array();
1. Assign to a file pointer named $fp the value obtained by calling fopen() with
the parameters "motocloz.txt" and "r";
2. Prepare a program fragment to input and store lists of names and costs from
the file "motocloz.txt". Each "line" of input contains five tokens: an id,
name, category, cost and quantity. Only name and cost are to be stored in
the parallel arrays. The name begins in position 6, has a length of 25, and
cost starts in 44 with length 6. The iteration structure for this process
is to repeat while more data exists in "motocloz.txt"
3. Close the file pointer for "motocloz.txt".
4. Locate the name "Shirt" and print the corresponding cost amount.
5. Sort the data from $name and $cost so the name and corresponding cost values
are in sequence. Print the sorted data.