0

In the following foreach loop, how would I access the value of $url?

 foreach ( $this->sessions as $i => $url ) curl_multi_add_handle( $mh, $this->sessions[$i] ); … 

I am trying to understand how that value for the url would be accessed for each particular cycle of the loop.

1
  • 2
    You would simply use $url within the loop, what's the issue? Commented Jun 7, 2014 at 0:13

1 Answer 1

5

You just use the variable:

foreach ( $this->sessions as $i => $url ) { curl_multi_add_handle( $mh, $url ); } 

Also, get in the habit of always putting braces around the body of for, foreach, if, while, etc., even if it's just one line. It prevents difficult-to-find errors in the future.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.