Skip to content

Instantly share code, notes, and snippets.

@Sitebase
Created March 11, 2013 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sitebase/5134567 to your computer and use it in GitHub Desktop.
Save Sitebase/5134567 to your computer and use it in GitHub Desktop.
Use array explode in combination with list and support different number of array items. In this example $params can have one, two or three items. Not set items will be null.
list($field1, $field2, $field3) = array_pad(explode('.', $params, 3), 3, NULL);
@Sitebase
Copy link
Author

  • It limits the size of the array returned by explode() to 2
  • If there are fewer than two values returned, it appends null until the array contains 2 values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment