Reputation: 73
this must be very simple but I couldn't make it work.. PHP noob :P
I have this array "$e_cats" and when I do var_dump($e_cats); the result is this:
array(3) { [0]=> string(3) "192" [1]=> string(3) "190" [2]=> string(3) "191" }
What I want is to add "-" to every value inside, so "-192", "-190", and "-191". Here is my code:
foreach ($e_cats as $cat) {
$cat = '-' .$cat;
}
but when I do print_r($cat) the result is: -191 (not all values). What did I do wrong?
Thanks in advance
Upvotes: 0
Views: 51
Reputation: 6269
foreach($e_cats as $i => $cat) {
$e_cats[$i] = '-' . $cat;
}
You were close!
Upvotes: 1