perl array increment equivalent in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reznorio
Forum Newbie
Posts: 1
Joined: Wed Sep 29, 2010 12:25 am

perl array increment equivalent in php

Post by reznorio »

Hi,

In perl, I can increment an array member by using this:
$strings{$1}++

what I want to do is assign a value to a dynamic array member ($i will be a variable) and increase in programatically.

is there something similar in php???
thanks in advance!
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: perl array increment equivalent in php

Post by twinedev »

Same in PHP

Wait, daggone font made it hard for me to see those were curly braces. It is the same if you use square brackets.

Code: Select all

$arySample = array('key1'=>5, 'key2'=>8, 'key3'=>10);

$strKey = 'key2';

$arySample[$strKey]++;

echo $arySample['key2'];  // Outputs 9


-Greg
Post Reply