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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.