You are here: array help « PHP Programming Language « IT news, forums, messages
array help

Posted by kurrent on 10/17/06 21:43

i'm still new to php and programming and was hoping to get some help on
a few questions i haven't had success in answering myself. I
successfully created my first very simple script to accomplish a task I
wanted, but not completely. see my code below:

<?php

//my first ever php program simply designed to automatically adjust new
prices of my properties

//current property prices
$prices = array('250000', '250000', '350000');

//percentage of how much to add to current prices
$increase_rate = '0.015'; // 1.15 %

//add new percentage to each price
foreach ($prices as &$newprice) {
$newprice = $newprice + ($newprice * $increase_rate);
}

//print out all new prices
for ($key = 0; $key < 3; $key++) {
print "$prices[$key]<br />";
}

?>

(forgive me if these questions seem completely common sense or stated
clearly in the php manual. I have done reading into these all day and
have gave up and so here I am)

HELP QUESTIONS:
---------------


1.) How would I make a copy of the old prices array that
was manipulated?

e.g. -> echo the following structure:
set an array of values, then do a function to
manipulate the values, then show the old
values in comparison of the new values
(basically, show that $253,750 used to be
$250,000)


2.) a) What if i have commas in my prices by default?

e.g. = array('349,502' '234,995');

b) How would I go about processing comma values
received via a form that a user entered or from .CSV
file that looked like (132,500, 123,340, 345,959,
244,459)?
c) How would I add a comma into my printed outputed values?

3.) There must be a better way to print out all the values
from an array but constructing a loop came to mind and
beats doing it one by one. Is there better way?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация