Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-27-2013, 09:32 AM   PM User | #1
needsomehelp
Regular Coder

 
Join Date: Oct 2009
Posts: 302
Thanks: 4
Thanked 3 Times in 3 Posts
needsomehelp can only hope to improve
unable to cycle through an array

I have created a counter of two variables for each user and trying to cycle through them so i can get the first and second variables if proving rather hard.

$mainCounters = array('userid' => '',
array( 'itemOwnerCommentCount' => 0, 'notItemOwnerCommentCount' => 0 )
);


I tried to use the foreach($newArray = $existingArray) {} but this fails with the following error... Invalid argument supplied for foreach()
Code:
foreach($mainCounter as $mainCounters) {
				?>[<? print_r($mainCounter);?>]<br><br><br><?
				//$a = $mainCounter[0];
				//$b = $mainCounter[1];
				}

How do I correctly access the array data one user at a time ?

in case it helps here is what a sample of the array may contain..

Array (
[100] => Array ( [0] => 1 [1] => 0 )
[ABC4EF] => Array ( [0] => 3 [1] => 0 )
[1] => Array ( [0] => 0 [1] => 0 )
[SDF5gH] => Array ( [0] => 0 [1] => 0 )
)

oh I know my userid is not a number, but with good reason, I have had a few ask this in the past ;-)

Last edited by needsomehelp; 01-27-2013 at 09:36 AM..
needsomehelp is offline   Reply With Quote
Old 01-27-2013, 10:07 AM   PM User | #2
needsomehelp
Regular Coder

 
Join Date: Oct 2009
Posts: 302
Thanks: 4
Thanked 3 Times in 3 Posts
needsomehelp can only hope to improve
ok came back to check if any replies, and just re-read my post, i found the bug... i had

foreach($mainCounter as $mainCounters) {

should be....

foreach($mainCounters as $mainCounter) {


but still there is a problem... the userid code is not showing...

i am trying to cycle through the userid code, and the two array variables, in turn.
needsomehelp is offline   Reply With Quote
Old 01-27-2013, 11:18 AM   PM User | #3
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
You should nest two foreach.

Like this:

PHP Code:
foreach($mainCounters as $mainCounter) {
//$mainCounter will have the array in userID so...

foreach($mainCounter as $key =>$value)
{

//First Iteration: $key = 'itemOwnerCommentCount'; $value = 0
//Second Iteration: $key = 'notItemOwnerCommentCount'; $value = 0;

}




__________________
For professional Hosting and Web design.....


NetEssentials.co.uk

Last edited by Redcoder; 01-27-2013 at 11:41 AM..
Redcoder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:52 AM.


Advertisement
Log in to turn off these ads.