Generate a valid array key from an URL string in PHP
Posted
by
John Riche
on Stack Overflow
See other posts from Stack Overflow
or by John Riche
Published on 2011-01-30T15:16:04Z
Indexed on
2011/01/30
15:25 UTC
Read the original article
Hit count: 157
I have a PHP array with some predefined values:
$aArray = array(
0 => 'value0',
1 => 'value1'
);
I need to create a function where the string input will always return the same, valid, array key so that when I call:
GiveMeAKey('http://www.google.com'); // May return 0 or 1
I receive always the same key (I don't care which one) from the array. Obvisously I can't store the relationship in a database and the string passed to the GiveMeAKey method can be any URL.
I wonder if there is a way of doing that ?
© Stack Overflow or respective owner