[PHP] next,key,current question
I am having trouble with creating a list box. I am attaching the code. I am not sure the code in the for loop close to the end of the program is correct. If someone could take a look at it I would appreciate it. Thanks, Sara My Class Schedule http://www.areawebdirectory.net/sealmark2.gif";> "; $Classes["DP237"] = "Programming Server Side Scripts"; $Classes["DP217"] = "Advanced CGI Programming"; $Classes["MA235"] = "Electronic Commerce"; // This funciton sorts the values in the array. asort($Classes); echo " This is using a while loop to create a list box."; echo ""; // Here we use the while loop to display the values in the array in a list box. while(list($ClassesKey,$ClassesValue) = each($Classes)){ echo "$ClassesValue"; } echo ""; echo "This is using a foreach loop to create a list box."; echo ""; // Here we use a foreach loop to create a list box from the Classes array. foreach ($Classes As $ClassesValue) { echo "$ClassesValue"; } echo ""; //The ksort function sorts the contents in the array by its indexes. ksort($Classes); echo "This is creating a list box by manually iterating through an array."; echo ""; // Here we will iterate through the array manually using a for loop and the next,current, and key functions. for($i=0; $i<3; $i++){ echo "$ClassesValue"; next($Classes); $CurrentIndexValue = key($Classes); echo ($CurrentIndexValue); $CurrentContents = current($Classes); echo ($CurrentContents); } echo ""; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] tax functions
Hello, I am new to php. I am trying to learn functions. Can someone look at my code and tell me if I am on the right track or if I am doing something wrong? Here is the link where my script can be found: http://www.areawebdirectory.net/taxfunction.txt Thanks, Sara D. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fighting with functions
I could use a little help. click on the link to see my php code for a project that creates an array with a list or items and their cost and calculates tax by using a function called getTax() and also creates a balance by adding the cost plus the tax in a second function called getBalance(). I must also create a table where the cells automatically load so the end result looks like this. http://www.areawebdirectory.net/taxtable2.txt Item Cost Tax Running Total Car 1.00600 10600.00 Pencil 1.00 .0610601.06 Book14.95 .097 10616.98 I cant seem to first be able to declare my array and succeed at naming the key as item and the value as price. I have attempted to use variations of the following with no success. $items = array ( 0 => array ("item"=>"car","price"=>15000, "tax"=>.065 ), 1 => array ("item"=>"pencil","price"=>1, "tax"=>.065 ), 2 => array ("item"=>"book","price"=>14.95, "tax"=>.065) ); Without being able to declare the key as item and the value as price I am not sure how to pass these items into my function and I am riddled with error messages. I think my base problem is to either fix how I am declaring the array so I may reference "item" and "price" as I am now doing in my functions or learn how to change the functions accordingly. I am also pretty sure that my functions are not quite right. I am also not sure how to link the right answers to get my table to print as above. Please note that I have included a while loop after my array just to prove that my array is working. It is needed part of my program. I also have given each cell in my table some text just so I can find them when I have figured out how to create the right reference links. I am sorry that I need as much help with this. Sadly I have been at this for almost two weeks trying to solve it. Thanks, Sara -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php