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 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    60
    Thanks
    1
    Thanked 0 Times in 0 Posts

    array, getting a certain key value

    This does not work.....

    foreach ($this->array_value as $key=>$value) {
    $thing = "$key";
    $ring = "$value";
    if ($thing == 'verify_sign'){
    echo 'this is the verify_sign' . $ring;
    }
    }

    This outputs the array

    foreach ($this->array_value as $key=>$value) {
    $text .= "$key=$value \n";

    }

  • #2
    New Coder
    Join Date
    Nov 2011
    Location
    Ratio, Logic
    Posts
    61
    Thanks
    3
    Thanked 6 Times in 6 Posts
    PHP Code:
    foreach ($this->array_value as $key => $value) {
      if (
    $key == 'verify_sign')
      {
        echo 
    'this is the verify_sign' $ring;
      }

    Like this?

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    60
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Tried, that doesn't work

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    60
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Figured it out

    Thanks for your time,

    I was doing it right, but forgot I wasn't echoing it, I was making a text file. Silly rabbit, trix are for kids.....

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This is a lot of work for something of a known associative index. Since you're not using an else clause, why would you use a foreach? Just access it directly:
    PHP Code:
    if (isset($this->array_value['verify_sign']))
    {
        
    printf($this->array_value['verify_sign']);

    Access goes from a O(n) to an O(1). Much faster.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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