Forum Moderators: coopster
How to tell php that the array needs to be reset / cleared / set to zero?
I've tried reset ($ar) and unset ($ar) but both won't work :(
$ar = array( $this->_movieValues['1'] => $row['1price'], $this->_movieValues['2'] => $row['2price'], $this->_movieValues['3'] => $row['3price'], $this->_movieValues['4'] => $row['4price'], $this->_movieValues['5'] => $row['5price'], $this->_movieValues['6'] => $row['6price'], $this->_movieValues['7'] => $row['7price'], $this->_movieValues['8'] => $row['8price'], $this->_movieValues['9'] => $row['9price']);asort ($ar);
foreach ($ar as $key => &$val){
$this->_movieValues['sorted'] .="$key";
}
Any help on this matter is much appreciated..
with the code above, it does give me the correct prices with each product but displays them like this:
PRODUCT 1
- PRODUCT 1 PRICE 1
to
- PRODUCT 1 PRICE 9
PRODUCT 2
- PRODUCT 1 PRICE 1
to
- PRODUCT 1 PRICE 9
- PRODUCT 2 PRICE 1
to
- PRODUCT 2 PRICE 9
PRODUCT 3
- PRODUCT 1 PRICE 1
to
- PRODUCT 1 PRICE 9
- PRODUCT 2 PRICE 1
to
- PRODUCT 2 PRICE 9
- PRODUCT 3 PRICE 1
to
- PRODUCT 3 PRICE 9
So I need to show only the price of PRODUCT 3 with PRODUCT 3 and was guessing that this error was caused due to the array not being cleared.
$ar = array(
$this->_movieValues['1'] < this is the HTML that has to be shown
=> $row['1price'] < this is the price in the DB
, $this->_movieValues['2'] => $row['2price'], $this->_movieValues['3'] => $row['3price'], $this->_movieValues['4'] => $row['4price'], $this->_movieValues['5'] => $row['5price'], $this->_movieValues['6'] => $row['6price'], $this->_movieValues['7'] => $row['7price'], $this->_movieValues['8'] => $row['8price'], $this->_movieValues['9'] => $row['9price']);
asort ($ar); < sort the array on price, low to high
foreach ($ar as $key => &$val){
$this->_movieValues['sorted'] .="$key"; < for every product show all prices ($row['1price'] to $row['9price']) with their correspondent HTML
}