{"id":936,"date":"2013-01-31T16:52:59","date_gmt":"2013-01-31T16:52:59","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=936"},"modified":"2022-02-17T07:14:03","modified_gmt":"2022-02-17T07:14:03","slug":"converting-arrays","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/memory\/arrays\/converting-arrays","title":{"rendered":"Converting Arrays"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Converting an array to individual variables<\/h4>\n\n\n\n<p>Argument lists may include the \u2026 token to denote that the function accepts a variable number of arguments. The arguments will be passed into the given variable as an array; for example:<\/p>\n\n\n\n<p>You can use &#8220;\u2026&#8221; with an array when calling functions to unpack the array or Traversable variable or literal into the argument list of individual variables.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyArrayValues = array();\n  $MyArrayValues&#91;] = \"A\";\n  $MyArrayValues&#91;] = \"B\";\n  SomeFunctionExpectingIndividualVariables($SomeValue, ...$MyArrayValues);\n\nfunction SomeFunctionExpectingIndividualVariables ($Value1, , mixed &amp;$var1 &#91;, mixed &amp;$... ])<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert array to a string<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$MyString = implode(\", \", $MyArray);    \/\/Outputs each element seperated by \", \"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Converting Strings To Numeric Arrays<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>function ConvertByteStringToByteArray($s)\n{\n\treturn array_slice(unpack(\"C*\", \"\\0\".$s), 1);\n}\n\nfunction ConvertByteArrayToByteString(array $t)\n{\n\treturn call_user_func_array(pack, array_merge(array(\"C*\"), $t));\n}\n\nfunction lsbStr2ushortArray($s)\n{\n\treturn array_slice(unpack(\"v*\", \"\\0\\0\".$s), 1);\n}\n\nfunction ushortArray2lsbStr(array $t)\n{\n\treturn call_user_func_array(pack, array_merge(array(\"v*\"), $t));\n}\n\nfunction lsbStr2ulongArray($s)\n{\n\treturn array_slice(unpack(\"V*\", \"\\0\\0\\0\\0\".$s), 1);\n}\n\nfunction ulongArray2lsbStr(array $t)\n{\n\treturn call_user_func_array(pack, array_merge(array(\"V*\"), $t));\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Converting an array to individual variables Argument lists may include the \u2026 token to denote that the function accepts a variable number of arguments. The arguments will be passed into the given variable as an array; for example: You can use &#8220;\u2026&#8221; with an array when calling functions to unpack the array or Traversable variable [&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-936","post","type-post","status-publish","format-standard","hentry","category-arrays"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/936","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=936"}],"version-history":[{"count":5,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/936\/revisions"}],"predecessor-version":[{"id":3903,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/936\/revisions\/3903"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}