the problem is, when you do it the second way, it drops the leading zero off
the number.

and the first way you are telling it that you are setting a string.


Try this.

print_r(array(001,'001',002,'002'));

you will notice that on two of them, you don't see the leading zeros, that
is because normal integers do not retain their leading zeros even if you
enter them.

Jim Lucas

----- Original Message ----- 
From: "Merlin" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, August 30, 2003 9:02 AM
Subject: [PHP] Re: trouble with array_search


> I printed the values out, and inserted it into a varibble to check if it
> finds it. In this case it works! But it only wokes if I do it like this:
>
> array('03042003');
>
> This does not work:
> array(03042003);
>
> So I gues it has something to do with this? It really drives me crecy, I
> already spent an hour on it :-(
>
> Merlin
>
>
>
> Catalin Trifu wrote:
>
> >     Hi,
> >
> >   You don't have to convert to string; PHP does it
> > automatically.
> >   Did you check for the $dates array, does it really contain
> > what you think it should.
> >   So, try to make a print_r($dates) and see if you have what you expect.
> >   FYI: array_search() returns the key of the last found element
> > (if any)
> >
> > Cheers,
> > Catalin
> >
> >
> >> Hi there,
> >>
> >> I am having somee trouble with array_search.
> >>
> >> The function should search for a given date, but it does not work
> >> since array_search seems only to compare strings. Thats why I tryed to
> >> cast it, but does not help.
> >>
> >> Here is the problem:
> >>
> >> (pseudo code)
> >>
> >>
> >> while(...
> >>     $log[date][]     = (string)date('mdY',$row->timestamp)
> >>
> >> $date_search = '03042003';
> >>
> >> $search = array_search($date_search, $dates);
> >> if ($search !== NULL)
> >>     echo 'works';
> >>
> >> it always returns 0
> >>
> >> Thanx for any help on that,
> >>
> >> Merlin
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to