php - Finding entry in array and putting it first or swapping with the first array entry -


i have php array full of arrays , want search through array chosen entry , swap first entry in array if makes sense...

so example below have chosen penny either go before bob or swap places bob.

my array looks this:

$people = array( array('bob', 'wilson'), array('jill', 'thompson'), array('penny', 'smith'), array('hugh', 'carr') ); 

i have tried using array_search don't think doing correctly.

for ($i = count($array) - 1; $i > 0; $i--) {     if ($array[$i][0] == $first_name) { // or whatever want search? in_array...?         $searched_array = array_splice($array, $i, 1);         array_unshift($array, $searched_array[0]);     } } 

this prepending. if want swap, see answer of @iamnotprocrastinating


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -