-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];"?

mck
  • 33,250
  • 12
  • 23
  • 39
  • 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.) – CherryDT Mar 08 '20 at 02: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. – CherryDT Mar 08 '20 at 02:29
  • Use this answer to extract URLs from a string, the string in this case being the curled web page: https://stackoverflow.com/a/36564776 – iJamesPHP2 Mar 08 '20 at 02:31
  • Does this answer your question? [Reference — What does this symbol mean in PHP?](https://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – Sherif Mar 08 '20 at 02:53

1 Answers1

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.

Jeff Huang
  • 565
  • 2
  • 10