\n"; echo "Original List: $groceryList[0] $groceryList[1] $groceryList[2] " . "$groceryList[3] $groceryList[4] $groceryList[5]\n"; echo "list count = " . count($groceryList) . "\n\n"; // 3 $groceryList = array(); // 4 $fp = fopen("list.txt","r"); while ( $groceryItem = fgets($fp ) ) { $groceryList[] = trim($groceryItem); } echo "New list (from file with \"trimmed\" data and string lengths):\n"; foreach($groceryList as $gL ) { echo "$gL\t" . strlen($gL) . "\n"; } echo "\n"; $itemToFind = "coffee"; // 5 $ndx = -1; for ($gx = 0; $gx < count($groceryList); $gx++) { if ( trim($groceryList[$gx]) == $itemToFind ) { $ndx = $gx; } } echo "search returned $itemToFind from cell $ndx \n\n"; $replacement = "tea"; // 6 echo "$itemToFind replaced with $replacement\n\n"; if ($ndx != -1) $groceryList[$ndx] = $replacement; echo "Updated list:\n"; // 7 foreach($groceryList as $gL ) { echo "$gL\n"; } echo "\n"; sort($groceryList); // 8 echo "Sorted list:\n"; foreach($groceryList as $gL ) { echo "$gL\n"; } ?>