Re: in_array w/statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



yeah, you're right though.. i had to use explode not implode

eg, if(in_array($uname['uid'], explode(' ', trim($userinfo['buddylist']))))
so i ditched the preg_split()

cheers.

----- Original Message ----- 
From: "Jason Wong" <php-general@xxxxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Thursday, December 16, 2004 3:39 PM
Subject: Re:  in_array w/statement


> On Friday 17 December 2004 02:33, Sebastian wrote:
>
> > I cannot solve this problem,. sorry if this looks confusing,.
>
> It is ...
>
> > i have a form and don't want to set the variable if the in_array is
true..
> > the code works, up until i add the last !$buddy in the statement, for
some
> > reason it seems to always be true, ... something i'm doing wrong? btw, i
> > cannot add the in_array to the statement because if the $buddylist is
empty
> > it will generate errors because of the empty implode.
> >
> > $buddylist = preg_split('/( )+/', trim($userinfo['buddylist']), -1,
> > PREG_SPLIT_NO_EMPTY);
>
> OK, it looks like $userinfo['buddylist'] is a string containing buddies
> separated by some whitespace:
>
>   'buddy1 buddy2'
>
> After the above statement $buddylist becomes an array.
>
> > if($buddylist)
> > {
> >  $buddy = in_array($uname['uid'], array(implode(',', $buddylist)));
> > }
>
> Here implode() returns a string containing 'buddy1,buddy2', then you stick
> that into an array() which is effectively:
>
>   array('buddy1,buddy2'); // note that there is only *1* element
>
> Now unless your $uname['uid'] really is literally 'buddy1,buddy2' then
$buddy
> will be false.
>
> Hope that's enough to get you going.
>
> -- 
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> ------------------------------------------
> Search the list archives before you post
> http://marc.theaimsgroup.com/?l=php-general
> ------------------------------------------
> /*
> The moon is made of green cheese.
>   -- John Heywood
> */
>
> -- 
> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux