/    Sign up×
Community /Pin to ProfileBookmark

How To Compare One Array Keys & Values Against Another Array ?

Folks,

This is valid array keys and valid array values:

““
$query_strings_array = array(
“find” => “keyword”,
“tbl” => “links”,
“col” => “keyword”,
“max” => “100”
);
““

They are actually params of a url.
And so, if the current page does not have these params in it’s query strings or the current page’s url has no query strings for that matter, then the current page is invalid. That’s what I want to check for.
So how to do it ?
I doing like this so far ….

““
//FETCH URL
if(isset($SERVER[‘HTTPS’]) && $SERVER[‘HTTPS’] === ‘on’)
{
$url = “https://”;
}
else
{
$url = “http://”;
}
// Append the host(domain name, ip) to the URL.
$url.= $_SERVER[‘HTTP_HOST’];
// Append the requested resource location to the URL
$url.= $_SERVER[‘REQUEST_URI’];
echo $url; echo ‘<br>’;
echo ‘<b>’ .__LINE__ .'</b>’; echo ‘<br>’;

if(filter_var($url, FILTER_VALIDATE_URL) && filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_QUERY_REQUIRED))
{
$scheme = parse_url($url, PHP_URL_SCHEME);
$host = parse_url($url, PHP_URL_HOST);
$path = parse_url($url, PHP_URL_PATH);
$query_strings = parse_url($url, PHP_URL_QUERY);
//parse query into array
parse_str($query_strings, $query_strings_array2);
//separate keys & values
$query_strings_keys = array_keys($query_strings_array2);
$query_strings_values = array_values($query_strings_array2);
}
““

So now, I got the current page’s url saved in $url. And I got the query string params saved on these:
$query_strings_keys = array_keys($query_strings_array2);
$query_strings_values = array_values($query_strings_array2);
Now, how do I check the keys and values of $query_strings_array2 against $query_strings_array ?

This won’t do will it as I need to do the Boolean thingy here if I really want to compare two arrays …

[code]
if($result=array_diff_assoc($query_strings_arra1,$query_strings_array2))
{
echo ‘Array keys & values are Identical!’
}
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...