Jump to content

display current username first from array


doddsey_65

Recommended Posts

Example: i have an array of names

array{

[0] => john

[1] = ted

[2] = jeff

}

 

and i display them like this:

 

john, ted, jeff

 

but jeff is currently logged in so i want his name to display first(i have my reasons lol)

 

how would i go about this?

i got as far as:

 

if(in_array($user->user_name, $likes))
            {
                $user_key = array_search($user->user_name, $likes);
            }

 

then hit a brain freeze.

 

Thanks

thanks for the reply. Since my actual array contained info like

array{

[0] => username1

[1] => date1

[2] => username2

[3] => date2

}

 

i simply used this:

 

if(in_array($user->user_name, $likes))
            {
                $user_key = array_search($user->user_name, $likes);
                
                $date = $likes[$user_key+1];
                $date_key = array_search($date, $likes);
                
                unset($likes[$user_key]);
                unset($likes[$date_key]);
                
                array_unshift($likes, $user->user_name, $date);
            }

 

thanks for the help

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.