Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    How do I get a max number of elements in my array ?

    Hi,

    I am creating an array from a table,
    (if I can get it to work - see other thread)

    Because it is dynamic, I do not know how many elements
    the array will contain. But I do want to only have a maximum of 60
    and these 60 must be the last 60 elements.

    Most of the time the number of elements will be lower than 40, but I must make sure that it is less than 61 elements.

    So if my array has (data1, data2, ... data60, data61, data62, data63)

    then I want to strip out the first three data elements and leave the last 60 in the array.

    Does anyone know how I can achieve this ?

    Thanks



    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    http://www.php.net/array_slice
    PHP Code:
    $max   60;
    $count count$items );

    if ( 
    $max $count )
    {
        
    $items array_slice$items$count $max );

    Untested, but that should do the trick.

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for that,

    I would not have thought about a function called "array_slice"

    anyway I checked it out in the manual and it looks just what I want.

    BTW - can you see what my problem is in this thread?

    Trying to understand variable variables

    Thanks again.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.


  •  

    Posting Permissions

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