Arrays.

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
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Arrays.

Post by JellyFish »

I need to learn more about arrays. If there is a site you know of that explains everything about php arrays, send it to me.

My basic question is, Can an array look like?: $array[1][4]

Any other help on this subject is appreciated.

Thanks for reading.
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Re: Arrays.

Post by ambivalent »

EasyGoing wrote: My basic question is, Can an array look like?: $array[1][4]
Yes
php.net - arrays
Ch 5 - Arrays

HTH
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

I've been looking around and for some reason I can't find how to get the length of an array?

How do you get the length of an array? In other words, how do you return the length of an array?
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

EasyGoing wrote:I've been looking around and for some reason I can't find how to get the length of an array?
Read Ch 5.1again, it contains valuable information with respect to the count() function.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

So count($myarray) would return my arrays length. All right, thanks. :)
Li0rE
Forum Commoner
Posts: 41
Joined: Wed Jun 07, 2006 6:26 am

Post by Li0rE »

if you mean the length of all the characters in the array, you can just to this

Code: Select all

<?php
$length = implode(" ", $array);
$length = strlen($length);

echo("This array contains $length characters.");
?>
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

No I just meant the length meaning how many values it has. But thanks for the post, it's good stuff. :D

How does the count function works? Does it start at 0 like the arrays index does? Or is the first value in the array 1?

For example if I put:

$length = count($myarray);

and my array has:

so, and, what, not

would the first value (so) be 0 in $length or would it be 1?
Post Reply