Creating Arrays

Use array();

Arrays in PHP can contain a mix of values if you wish (e.g. strings, integers, null, arrays).

Create an empty array
  $result_search = array();

//You can add items to it like this:
  $result_search[] = "a";
  $result_search[] = "b";
  $array = array_fill(0, 24, 0);    //Fill an array from index 0, 24 items long (0-23), with default value 0
Create an array of values
  $names = array('Adam', 'Bill', 'Charlie);
  echo $names[1];      //Displays Bill

  //Alternative method to create the same an array:
  $names = ['Adam', 'Bill', 'Charlie];

Calling a function with an array of values

soem_function_name(array('group_id' => $GroupId, 'exclude_admins' => false));

Key & Value Arrays

See here.

Two Dimension Arrays

See here.

Array Length

  count(MyArray)

Is Array?

  if (!is_array($my_array))

Is Array Empty

  if (empty($my_array))

Does array index exist?

  if (isset($matches[1]))
  {
//Another example
  return isset($args['v']) ? $args['v'] : false;

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.