check size of an array

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
mit
Forum Commoner
Posts: 32
Joined: Mon Sep 15, 2008 6:37 am

check size of an array

Post by mit »

I need to check size of an array which is in this format : $dref="score1;score2;score3;score4";
I need to check the size of this array if the score2,score3,score4 are empty return me 1 if score3,score4 are empty return me 2 , meaning to check how many of scores are having value.

like -> $dref="19;;;; "; = return me 1
$dref="19;18;;; "; =return me 2
$dref="19;18;40;; "; = return me 3
$dref="19;18;40;50; "; = return me 4(all)
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: check size of an array

Post by papa »

count()
mit
Forum Commoner
Posts: 32
Joined: Mon Sep 15, 2008 6:37 am

Re: check size of an array

Post by mit »

how can i use this count()? count will return me non empty one or all?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: check size of an array

Post by aceconcepts »

count will returnt he number of values in an array - http://uk3.php.net/count

Take a look at the PHP manual http://uk.php.net/array
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: check size of an array

Post by Mark Baker »

mit wrote:I need to check size of an array which is in this format : $dref="score1;score2;score3;score4";
This isn't actually an array. It's a string.

Code: Select all

 
$dref = "score1;score2;score3;score4";
$drefArray = explode(';',$dref);
echo '<pre>';
print_r($drefArray);
echo '</pre>';
 
Then start looking at the array functions described in the manual
Post Reply