user3162341
user3162341

Reputation: 251

How can i add +x for each array

I have an array which is like this :

foreach($keys as $tmpItem) {
            $item = null;
            $item['id']       = $tmpItem;
            $item['price']     = $prices[$tmpItem];
            $items[]          = $item;  
}

I want to add + 10 for each item in my array.

Item[0] = 10,

Item[1] = 20,

item[2] = 30

etc...

How can i do it ? Thanks

Upvotes: 0

Views: 34

Answers (2)

scrblnrd3
scrblnrd3

Reputation: 7426

You could just do this:

 $i=0;
 foreach($keys as $tmpItem) {
        $i+=10;

        $item = null;
        $item['id']       = $tmpItem;
        $item['price']     = $prices[$tmpItem];
        $items[]          = $i;  
 }

Upvotes: 1

Pedro Monteiro
Pedro Monteiro

Reputation: 337

You need this?

$aux=0;

foreach($keys as $tmpItem) {
            $aux = $aux+10;

            $item = null;
            $item['id']       = $tmpItem;
            $item['price']     = $prices[$tmpItem];
            $items[]          = $aux;  
}

Upvotes: 1

Related Questions