LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2011, 08:48 AM   #1
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Rep: Reputation: 79
PHP: Count number of value in sub array


Hello there,

I'm trying to count the number of value of my sub array which look like this:

$myArray[group1][0]

A var_dump of this array give me this:
array(1) {
["group1"]=>
array(2) {
[0]=>
string(9) "DCL1248ES"
[1]=>
string(9) "DHL1248ES"
}
}

I would like to count the number of value contain in $myArray[group1] that in this present case would give me 2

I've try with count($myArray[group1])
but the following code give me 1:
Code:
$arrayCount = count($myArray[group1]);
print "$arrayCount";
 
Old 08-24-2011, 11:22 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

From what you posted, it's impossible to say what's wrong. Is the var_dump of $myArray or $myArray[group1][0]?

This outputs 2:

PHP Code:
$myArray = array(
  
"group1" => array("DCL1248ES","DHL1248ES")
);
echo 
count($myArray["group1"]); 
 
Old 08-26-2011, 03:35 AM   #3
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Original Poster
Rep: Reputation: 79
I don't know what did I mess around, but you are right, the code I've typed in my ariginal post is working. I've just forgot the quote do.

Thanks for your light.
Angel.

Last edited by angel115; 08-26-2011 at 03:36 AM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] count how many number occurrences in series kpinto Linux - Newbie 4 06-02-2011 08:22 AM
count occurrency of each array element - Perl shifter Programming 19 05-12-2010 03:14 AM
PHP: Converting a PHP array into an HTML array koosha Programming 4 08-11-2009 08:47 AM
count number of used ports mnchur Linux - General 2 02-10-2009 02:11 PM
tcl newbie: can't count length of array jimieee Programming 12 06-03-2006 12:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration