Rapid search in a multi-dimensional area



  • There's a lot of content on your hands:

    Array (
    [show] => Array
        (
        [0] => Array
                (
                    [name] => Добрый динозавр
                    [id] => 3777
                    [alias] => dobrii-dinozavr-the-good-dinosaur
                 )
        [1] => Array
                (
                    [name] => Звёздные войны: Пробуждение силы
                    [id] => 3821
                    [alias] => zvezdnie-voini-probuzhdenie-sili-star-wars-the-force-awakens
    
            )
    [2] и так далее...
    

    Show me how best you can get. [id] If only [alias]?



  • For php constituent5.5.0, the idea is that:

    $key = array_search("dobrii-dinozavr-the-good-dinosaur", array_column($arr, 'alias'));
    echo $arr[$key]["id"];
    

    For the general case, and possibly for 5.5.0, it will be faster to maintain a pre-set of indices alias and contents . - id

    If you need to deliver different fields on the basis of the aliaths, build a set of keys. alias and numbers in the reference area. I mean, something like that:

    <?php
    $arr=array(array ("name" => "Добрый динозавр","id" => 3777,"alias" => "dobrii-dinozavr-the-good-dinosaur"),
               array ("name" => "Звёздные войны: Пробуждение силы","id" => 3821,
                    "alias" => "zvezdnie-voini-probuzhdenie-sili-star-wars-the-force-awakens")
              );
    $index=array();
    foreach($arr as $k => $v)
    {
     $index[$v['alias']]=$k;
    }
    print $arr[$index["dobrii-dinozavr-the-good-dinosaur"]]["id"];
    ?>
    

    If search occurs frequently in many of the violators &apos; challenges and a new baseline is rarely available. To record the information in the OBD system or at least prepare an index or converted body and put it somewhere, for example, through serialize




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2