SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array Question... brain blank.

    Hey,

    I have a pretty large array. For example purposes, lets say I have the following array:
    ( [testarray] => Array
    ( [0] => Array ( [0] => 403120 [item_number] => 403120 [1] => May 25 2009 12:00AM [date] => May 25 2009 12:00AM)
    [1] => Array ( [0] => 403134 [item_number] => 403134 [1] => Jun 1 2009 12:00AM [date] => Jun 1 2009 12:00AM)
    [2] => Array ( [0] => 404444 [item_number] => 404444 [1] => Jun 14 2009 12:00AM [date] => Jun 14 2009 12:00AM )

    How do I loop through this array called 'testarray' and display all of the information (in this case date, item number) only if item_number is equal to a certain number?

    I know I have done this before, cant find any of my old stuff to look at that.

    Thanks!

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Texas
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you need to loop through all the elements or can you use in_array()?

    http://www.php.net/in_array

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    foreach($aTestArray as $aItem)
    {
        if(
    $aItem['item_number'] === 40586)
        {
            
    // do something with $aItem
        
    }
    }
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Addict
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I need to loop through everything that matches a certain item number. There can be multiple elements matching the same item number. Then, if that item number is there, I need to output all the other information from that element?

    Edit: Just saw your answer SilverBullet, will give it a go.


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
  •