/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help with incrementing an array

Hi

i am trying to increment an array with a value from within a foreach loop.

here is the foreach loop:

[COLOR=”Red”]foreach($list as $item)
{

$row->set(‘STYLE’,$style);
$row->set(‘ID’,$item[‘Id’]);
$row->set(COMMENTS,$item[‘Comments’]);

}[/COLOR]

i want to create a new array and populate it with the Id value from the above loop.

i had this within the foreach but i dont think it is in the correct place as it seems to only contain the last value of the loop:

[COLOR=”Blue”]$faultArray = array();
$faultArray = $item[‘Id’];[/COLOR]

any help is appreciated

cheers!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ixxalnxxiJan 08.2009 — So you want to keep an arrays of ID? It would be,


[code=php]
//not 100% sure if declaration is needed but just incase
$faultArray = array();

foreach($list as $item)
{

$row->set('STYLE',$style);
$row->set('ID',$item['Id']);
$row->set(COMMENTS,$item['Comments']);
$faultArray[] = $item['Id'];
}
[/code]
Copy linkTweet thisAlerts:
@paulnicauthorJan 08.2009 — So you want to keep an arrays of ID? It would be,


[code=php]
//not 100% sure if declaration is needed but just incase
$faultArray = array();

foreach($list as $item)
{

$row->set('STYLE',$style);
$row->set('ID',$item['Id']);
$row->set(COMMENTS,$item['Comments']);
$faultArray[] = $item['Id'];
}
[/code]
[/QUOTE]


ok thanks! will will try it tomorrow when i get into work!

looks about right to me though, just missed the [] off!


thanks again
×

Success!

Help @paulnic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...