Home  >  Q&A  >  body text

How to create a fixed length array in php?

Someone asked me a question during the last interview. I was quite surprised. Do you have any good answers?

伊谢尔伦伊谢尔伦2737 days ago386

reply all(4)I'll reply

  • 迷茫

    迷茫2017-05-16 13:17:52

    SplFixedArray is a fixed-length standard (standard array) and only allows integers in the range as indexes. The advantage is that it allows faster array implementation.

    PHP arrays are actually implemented as ordered hash tables (a collection of data)

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-16 13:17:52

    I asked similar questions when interviewing others. What I asked was to write a data structure with 1000 rows * 1000 columns and the values ​​​​are all random numbers from 1 to 99. Many people did not know how to write it. This is obviously For the data structure test, in fact, all developers are playing with arrays, so I have requirements for this. It is very simple if you use two for loops to nest. As for the value, it is even simpler, mt_rand(1,99)... ...

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:17:52

    array_pad()

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 13:17:52

    The SplFixedArray class http://php.net/manual/zh/clas...

    reply
    0
  • Cancelreply