SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    finding out about an array

    i've tried various ways of finding out informatin about an array and completely failed

    then main thing i'm trying to do is find the number of the last row of variables (it's a multidimensional array)

    i've tried:

    echo count($myarray); - echos 5!! what the hell's 5 got to do with anything?!

    echo count($myarray[0]); - echos 0

    echo count($myarray[1]); - echos 0

    echo count($myarray[2]); - echos 0

    print_r(array_count_values($myarray)); - error (got that from the manual)

    print_r(array_count_values($myarray[0])); - same error again

    i've tried some other things but all have failed

    the array that i was using had about 40 rows and had 3 (maybe 4) elements to each row.

    so how do i find the end of an array?

    also how do i find out how wide an array is, if you know what i mean? - if it's a multidimensional array how many segments to each row are there?

    thanks

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how are you initializing this array ?

  3. #3
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,301
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    this is what creates the array -
    Code:
    preg_match_all("/(\d\d\:\d\d)[\s]*(.*)[\s]*(.*((?![\s]*\d\d\:\d\d)(?![\s]{3})[\s]*.*)*)/", $strippedhtmldoc, $myarray);
    but it's not too important how it gets there. it is there that's the main thing.
    when i print the whole thing out it's all there like this...
    Code:
    	
    // more php above here
    foreach($myarray[1] as $key => $val) {
    
    ?>
    
    	<textarea rows="1" cols="10"><?php print $myarray[1][$key]; ?></textarea> 
    	<textarea rows="2" cols="20"><?php print $myarray[2][$key]; ?></textarea> 
    	<textarea rows="10" cols="50"><?php print $myarray[3][$key]; ?></textarea> <br>
    
    <?php
    		}
    ?>
    ...no problem. there's 38 rows. the above print out prints 3 elements per row because that's all it's asking but there seems to be another element per row in the [0] position - the pregmatchall seems to have made a grouping of the three other elements in [1] [2] and [3] in the [0] box. maybe that's a standard feature of pregmatchall, or maybe the pregmatch that i'm using requests that but i don't think it does. inanycase, not important.

    the main thing i want to be able to ask in my code is how many rows? an d the answer would be in this particular situation 37 or 38 depending on whether you start from 0 or 1

    also i'd like to be able to ask how many elements does each row have?

    there must be a direct simple way to get that isn't there?
    Last edited by johnyboy; Jul 24, 2002 at 05:48.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •