Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Hello all,

    I want to know how I can retrieve an element from an array using just a standard index location, which begins at 0, of course. This is something that I would do in Java all the time, especially in a for loop.

    It might look something like this in Java (using the predefined indexOf() method):
    Code:
    {
      for (int i = 0; i < thisArray.size(); i++)
             String toBeTested = thisArray.indexOf(i);
             ....
             ....
    }

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    Are you seeking a location knowing the specific index ahead of time, or are you trying
    to find (or match) a string with an element in the array?


  4. #3
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    I am looking to index the location sequentially, using 'i' as the index as the for loop increments with i++.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    You can use the for-next:

    PHP Code:
    <?php
    $thisArray
    =array("zero","one","two","three");
    for(
    $i=0$i<count($thisArray); $i++){
    echo 
    $thisArray($i)."<br />";
    }
    ?>
    Or foreach ...

    PHP Code:
    <?php
    $thisArray
    =array("zero","one","two","three");
    foreach(
    $thisArray as $item){
    echo 
    $item;
    }
    ?>



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:54 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com