{"id":3914,"date":"2022-01-19T17:39:22","date_gmt":"2022-01-19T17:39:22","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=3914"},"modified":"2022-02-17T07:13:46","modified_gmt":"2022-02-17T07:13:46","slug":"key-value-arrays","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/memory\/arrays\/key-value-arrays","title":{"rendered":"Key => Value Arrays"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Key &amp; Value Arrays <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyKeyValueArray = array(\n    'comments' =&gt; $comments_count,\n    'responses' =&gt; $responses_count\n  );\n\n\n  \/\/Alternative method to create the same an array:\n  $MyKeyValueArray = &#91;\n    'comments' =&gt; $comments_count,\n    'responses' =&gt; $responses_count\n  ];<\/code><\/pre>\n\n\n\n<p>or create like this<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyKeyValueArray = array();\n  $MyKeyValueArray&#91;'comments'] = $comments_count;\n  $MyKeyValueArray&#91;'responses'] = $responses_count;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Accessing array keys and values<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  foreach ($MyKeyValueArray as $Key =&gt; $Value)\n  {\n    echo \"{$Key} =&gt; {$Value} \";\n  }<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>  foreach ($MyArray as $Item)\n  {\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Remove Array Value<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  unset($MyArray&#91;\"My index name\"]);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Key &amp; Value Arrays or create like this Accessing array keys and values Remove Array Value<\/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-3914","post","type-post","status-publish","format-standard","hentry","category-arrays"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/3914","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=3914"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/3914\/revisions"}],"predecessor-version":[{"id":3919,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/3914\/revisions\/3919"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=3914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=3914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=3914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}