“PHP -Suche mehrdimensionales Array für mehrere Werte” Code-Antworten

Multidimensionale Array -Suche von PHP nach Wert

$key = array_search('100', array_column($userdb, 'uid'));
Gleaming Gerbil

Array -Suche mehrdimensionales PHP

function find_customer_mobile($customers, $mobile) {
    foreach($customers as $index => $cust) {
        if($cust['mobile'] == $mobile) return $index;
    }
    return FALSE;
}
hmt

Multidimensionales Array der PHP -Gruppe nach Wert

function arraySort($input,$sortkey){
  foreach ($input as $key=>$val) $output[$val[$sortkey]][]=$val;
  return $output;
}
Indian Gooner

PHP -Suche mehrdimensionales Array für mehrere Werte

  /**
   * PHP Search an Array for multiple key / value pairs
   */

  function multi_array_search($array, $search) {
    // Create the result array
    $result = array();

    // Iterate over each array element
    foreach ($array as $key => $value){

      // Iterate over each search condition
      foreach ($search as $k => $v){

        // If the array element does not meet the search condition then continue to the next element
        if (!isset($value[$k]) || $value[$k] != $v){
          continue 2;
        }
      }
      // Add the array element's key to the result array
      $result[] = $key;
    }

    // Return the result array
    return $result;
  }

  // Output the result
  print_r(multi_array_search($list_of_phones, array()));

  // Array ( [0] => 0 [1] => 1 )

  // Output the result
  print_r(multi_array_search($list_of_phones, array('Manufacturer' => 'Apple')));

  // Array ( [0] => 0 )

  // Output the result
  print_r(multi_array_search($list_of_phones, array('Manufacturer' => 'Apple', 'Model' => 'iPhone 6')));

  // Array ( )
Nilesh

Ähnliche Antworten wie “PHP -Suche mehrdimensionales Array für mehrere Werte”

Fragen ähnlich wie “PHP -Suche mehrdimensionales Array für mehrere Werte”

Weitere verwandte Antworten zu “PHP -Suche mehrdimensionales Array für mehrere Werte” auf PHP

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen