doddsey_65 Posted February 22, 2011 Share Posted February 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/228539-display-current-username-first-from-array/ Share on other sites More sharing options...
requinix Posted February 22, 2011 Share Posted February 22, 2011 Remove it from the list and unshift it back on. Then it'll appear at the beginning. Quote Link to comment https://forums.phpfreaks.com/topic/228539-display-current-username-first-from-array/#findComment-1178378 Share on other sites More sharing options...
doddsey_65 Posted February 23, 2011 Author Share Posted February 23, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/228539-display-current-username-first-from-array/#findComment-1178709 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.