-1

I am trying to curl a url, then explode page into an array to extract line with a link. I have a sample script, but I don't know what the "135" means. I'm not very good with php. Any help would be appreciated, thank you in advance.

Sample code:

$code = explode(" ",$result);
echo $code[135];

Question: What does the "135" represent in "echo $code[135];"?

4
  • 1
    The 136th item in the resulting array. (Why not 135th? Because array indices start with the number 0 and not 1 as first index.) Commented Mar 8, 2020 at 2:27
  • If you have a string $s = 'ab cd ef gh'; and you do $a = explode(" ", $s);, then $a will be ["ab", "cd", "ef", "gh"] and therefore $a[0] will be "ab", $a[1] will be "cd" and so on. Commented Mar 8, 2020 at 2:29
  • Use this answer to extract URLs from a string, the string in this case being the curled web page: stackoverflow.com/a/36564776 Commented Mar 8, 2020 at 2:31
  • Does this answer your question? Reference — What does this symbol mean in PHP? Commented Mar 8, 2020 at 2:53

1 Answer 1

1

Square brackets after a variable generally represent the index of an array. In this case, the variable $code is and array. $code[135] is referencing the 135th index of the array. If you want to see the whole array to see what is going on, you can try using the var_dump() method.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.