Converting an array to individual variables

Argument lists may include the … 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 “…” with an array when calling functions to unpack the array or Traversable variable or literal into the argument list of individual variables.

  $MyArrayValues = array();
  $MyArrayValues[] = "A";
  $MyArrayValues[] = "B";
  SomeFunctionExpectingIndividualVariables($SomeValue, ...$MyArrayValues);

function SomeFunctionExpectingIndividualVariables ($Value1, , mixed &$var1 [, mixed &$... ])

Converting Strings To Numeric Arrays

function ConvertByteStringToByteArray($s)
{
	return array_slice(unpack("C*", "\0".$s), 1);
}

function ConvertByteArrayToByteString(array $t)
{
	return call_user_func_array(pack, array_merge(array("C*"), $t));
}

function lsbStr2ushortArray($s)
{
	return array_slice(unpack("v*", "\0\0".$s), 1);
}

function ushortArray2lsbStr(array $t)
{
	return call_user_func_array(pack, array_merge(array("v*"), $t));
}

function lsbStr2ulongArray($s)
{
	return array_slice(unpack("V*", "\0\0\0\0".$s), 1);
}

function ulongArray2lsbStr(array $t)
{
	return call_user_func_array(pack, array_merge(array("V*"), $t));
}
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.