undefined offset when using php explode()

后端 未结 7 2014
闹比i
闹比i 2020-12-03 17:07

I\'ve written what I thought was a very simple use of the php explode() function to split a name into forename and surname:

// split name into f         


        
7条回答
  •  感动是毒
    2020-12-03 17:32

    Use array_pad

    e.q.: $split = array_pad(explode(' ', $fullname), 2, null);

    • explode will split your string into an array without any limits.
    • array_pad will fill the exploded array with null values if it has less than 2 entries.

    See array_pad

提交回复
热议问题