|
Posted by Csaba Gabor on 06/14/06 14:34
Paul Lautman wrote:
> > When I enter
> > 'http://localhost/template.php?page=plan2', I get the default 'home'
> > page.
> >
> > For the life of me I don't see what is wrong.
> > <?php
> > $allpages=array(
....
> > 'The Plan'=>'plan1',
> > 'The Plan'=>'plan2',
> > 'The Plan'=>'plan3'
> > );
>
> Further on the actual problem, it seems that if a key value is repeated,
> then array_search will only return that key if the value found is the last
> one in the list with the same keys. So for your example, it'll work for
Without intending bearing on the OP's problem ... If you want to search
for multiple instances of the same value in an array, you can use
array_intersect to return all the matching instances, complete with
original keys:
$aRes = array_intersect($allpages, array("search term"));
So if you wanted to get the last matching key you could do:
$lastKey = array_pop(array_keys(array_intersect($allpages,
array("search term"))));
Csaba Gabor from Vienna
Navigation:
[Reply to this message]
|