SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Printing one key of an array

    I am using a for loop to access certain keys in an array that I have got from a database. If the key is set, then I would like to print the key name, not the value.

    So far, the code looks like this:
    PHP Code:
    for ($i=19$i<27$i++)
        {
            if isset(
    $row['$i'])
            {
                
    //I don't think I can use a foreach here, because I only want to print one key, not all 

  2. #2
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can get key from foreach cycle

    PHP Code:
    foreach ( $array as $key=>$value ){
       if ( isset( 
    $row[$key] ) ){
          
    // do smth
       
    }


  3. #3
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $array $_POST["hey"];
    foreach(
    $array as $key) {
    print(
    $key);


  4. #4
    SitePoint Wizard subnet_rx's Avatar
    Join Date
    Aug 2001
    Location
    Hattiesburg, MS
    Posts
    1,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I only want to print out certain keys like 15-26, not the entire array.


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
  •