How do you replace a number of symbols with their numbers?



  • There's a line of view.

    11010010101101
    

    and the key, the mass, for example:

    array(
    '3' => '1', 
    '5' => '1', 
    '10' => '1'
    );
    

    The line is stored in the database, the key is transferred to $US$ _SESSION

    The idea is that by taking the line from the base, item 3, 5, 10 is replaced from 0 to 1 (the count of entries begins with 1). That is, the line of the species shall be taken out:

    11111010111101

    I tried through. str_split() I can't figure out how the two setslines (lines and keys) get to the desired effect.

    This set of keys is given for example, it itself is dynamic and may have between 1 and the number of symbols in a variable line (in this case 14) cells.

    UPD:by decision below, acted as

    function genNew($word, $key_array=array())
    {
        $split_word = str_split($word);
        foreach ($key_array as $key => $array_elements)
        {
            $split_word[$key-1] = $array_elements;
        }
    
    $new_word = implode($split_word);
    
    return $new_word;
    

    }



  • The battle line up to 32 symbols can be stored as integer.
    For a key of 14 symbols length, operation $n |= 1<<13-2 Sets the 3rd in battle

    Get the key to the line, you can have a team. sprintf("%14d", $n, $str)




Suggested Topics

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