php - How find Row Number of Value within Array? -


i've saved data array, , want 'name' of supplied 'code'.

how array row of code?

also, efficient process?

 id  |  code  |  name     |   __________________________ 1   |  knty  |  kentucky | 2   |  purd  |  purdue   | 3   |  texs  |  texas    |   // move data array $search = "select * table"; $query = mysqli_query($conn, $search); while($row = mysqli_fetch_assoc($query)) {    $array[] = $row; }  // code want name $code = "knty"; // mystery step need $name = $array[$id]['name']; 

i edit hint of comment of itachi. can use code key of $array:

$search = "select * table"; $query = mysqli_query($conn, $search);  $array = array();  while($row = mysqli_fetch_assoc($query)) {    $array[$row['code']] = $row['name']; }  // code want name $code = "knty";  $name = $array[$code]; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -