simonmlewis wrote:How do you extract that number (13) out of $vars, into one held variable?
That means, if you want individual variables instead of an array, do not give $vars to parse_str().McInfo wrote:Instead, if not given a second argument, parse_str() will create variables in the current scope that have the same names as those in the given query string.
Code: Select all
parse_str(parse_url($url, PHP_URL_QUERY));Code: Select all
$page = "selector";
$menu = "home";
$id1 = "397";
$id2 = "13";
$id3 = "";
$id4 = "";
$id5 = "";If $vars is an array, you can specify a key to get the associated value.simonmlewis wrote:There are potentially five 'id*' in $vars, but how do you get each one
Code: Select all
$vars['id1']Code: Select all
$key = 'id1';
$vars[$key]Code: Select all
$key = 'id' . '1';
$vars[$key]Code: Select all
$n = 1;
$key = 'id' . $n;
$vars[$key]Code: Select all
$n = '1';
$vars['id'.$n]Code: Select all
$n = 1;
${'id'.$n} // Same as $id1Code: Select all
$n = 2;
$key = 'id' . $n;
${$key} // Same as $id2Code: Select all
$n = '1';
$key = 'id' . $n;
$$key // Same as $id1The empty() function will test that.simonmlewis wrote:and if one is empty, how does you make the script aware?
Code: Select all
empty($vars['id1'])Code: Select all
empty($id1)