[code]
<?php
$url = ‘http://www.google.com/?search=cars’;
print_r(explode(‘?’,$url));
?>
It’s obvious, the explode divided the url into 2 parts. One part of data before the “?” and the other part after the “?”. And then it dumped the two data onto an array and that’s why we need to use print_r to check the two data and cannot just use echo to check the two data. But what exactly is the array called where the two data got dumped ?
You see, usually we know what the array is called because we assign a named variable to it.
I mean, usually when we create arrays we name it with a variable like so:
$arr = array();
Then we dump data onto it like so:
$arr[] = ‘blah;’
And so, we know what the array is called. In this case $arr.
But in the following case, what is the array called where the 2 data (2 parts of the url) got dumped ? What variable did php assign to the array ?
I mean, php did auto create, in the background an array, and dump the two data there. Or, how else can we print_r(explode) ? afterall, you view the data (values) of array with print_r as you cannot with echo without doing a loop.
[code]
<?php
$url = ‘http://www.google.com/?search=cars’;
print_r(explode(‘?’,$url));
?>
If I can know the array’s var name then I can loop like this:
[code]
<?php
foreach($array_var AS $value)
{
echo $value;
}
?>