{"id":158,"date":"2012-01-30T21:36:40","date_gmt":"2012-01-30T21:36:40","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=158"},"modified":"2026-04-09T16:34:43","modified_gmt":"2026-04-09T15:34:43","slug":"arrays-general","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/memory\/arrays\/arrays-general","title":{"rendered":".Array General"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Creating Arrays <\/h4>\n\n\n\n<p>Use array(); <\/p>\n\n\n\n<p>Arrays in PHP can contain a mix of values if you wish (e.g. strings, integers, null, arrays).<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Create an empty array <\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $result_search = array();\n\n\/\/You can add items to it like this:\n  $result_search&#91;] = \"a\";\n  $result_search&#91;] = \"b\";<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>  $array = array_fill(0, 24, 0);    \/\/Fill an array from index 0, 24 items long (0-23), with default value 0<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Create an array of values <\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyArray = array('Adam', 'Bill', 'Charlie);\n  echo $MyArray&#91;1];      \/\/Displays Bill\n\n  \/\/Alternative method to create the same an array:\n  $MyArray = &#91;'Adam', 'Bill', 'Charlie];\n\n  $MyArray = array(\n                   'key_name_1' =&gt; \"Hello\",\n                   'key_name_2' =&gt; false,\n                   'key_name_3' =&gt; 1234\n            );<\/code><\/pre>\n\n\n\n<p>Get array value<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyString= $OperationUsageJson&#91;'MyString'] ?? '';\n  $MyValue = $OperationUsageJson&#91;'MyValue'] ?? 0;<\/code><\/pre>\n\n\n\n<p>(Gets the array value if it exists, otherwise to an empty string\/int)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Calling a function with an array of values<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>soem_function_name(array('group_id' =&gt; $GroupId, 'exclude_admins' =&gt; false));<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Key &amp; Value Arrays <\/h4>\n\n\n\n<p>See <a href=\"\/cloud\/php\/memory\/arrays\/key-value-arrays\">here.<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Two Dimension Arrays <\/h4>\n\n\n\n<p>See <a href=\"\/cloud\/php\/memory\/arrays\/multidimensional-arrays\">here<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Array Length <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  count($MyArray)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Is Array?<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (!is_array($my_array))<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Is Array Empty <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (empty($my_array))<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Does array index exist? <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&nbsp; $MyArrayValue = isset($MyArray&#91;'some_name']) ? $MyArray&#91;'some_name'] : '';\n\n\/\/Another example\n  return isset($args&#91;'v']) ? $args&#91;'v'] : false;\n\n\/\/Another example\n  if (isset($MyArray&#91;1]))\n  {\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Does array value exist?<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (in_array('Test', $MyArray))\n  {\n    \/\/Value exists\n  }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 Create an array of values Get array value (Gets the array value if it exists, otherwise to an empty string\/int) Calling a function with an array of values Key &amp; [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-arrays"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":52,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":5355,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/158\/revisions\/5355"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}