The Codesee The Codesee - 5 months ago 10
HTML Question

Get URL Variable From Array

I am trying to get the URL variable

from a list of objects in an array and display them.

Current Code:

$display = print_r($array);
echo $display;


Array ( [0] => [1] => [2] => [3] => )

I would like the display each URL variable
from the array inside a


I have tried to do this using the following code but no luck:

foreach($display as $display2) {
echo '<div>'.$_GET['ID'].'</div>';


The $_GET super global is for accessing query-string values from the current request, not for reading them out of an arbitrary url stored in a string.

But fret not, PHP's standard library has functions to help, namely parse_url() and parse_str()

foreach($display as $url) {
   $queryString = parse_url($url, PHP_URL_QUERY)
   parse_str($queryString, $parameters)
   echo '<div>'.$parameters['ID'].'</div>';