View Source PhpAssocMap (PhpAssocMap v3.0.0)
Summary
Functions
Gets the document AST from leex and yecc parser. The ast is automatically obtain from to_tuple/1 and to_map/1
Converts a map structure to an associative array string. The string key and value are single quoted
Converts a keyword list structure to an associative array string. The string key and value are single quoted
Parses an associative array string (or charlist) to a key-valued map. Both single and double quotes are supported.
Parses an associative array string (or charlist) to a key-valued keyword list. Both single and double quotes are supported.
Functions
Gets the document AST from leex and yecc parser. The ast is automatically obtain from to_tuple/1 and to_map/1
Exmples
iex> PhpAssocMap.ast("['key'=>['another_key'=>'value']]")
[{"key", [{"another_key", "value"}]}]
@spec from_map(map(), PhpAssocMap.Exploder.spacing()) :: binary()
Converts a map structure to an associative array string. The string key and value are single quoted
The returned document will not be formatted yet. Use PhpAssocMap.Exploder.explode/1 or PhpAssocMap.Exploder.explode/2 to have it formatted.
Exmples
iex> PhpAssocMap.from_map(%{"key" => %{"another_key" => "value"}})
"['key'=>['another_key'=>'value']]"
@spec from_tuple([tuple()], PhpAssocMap.Exploder.spacing()) :: binary()
Converts a keyword list structure to an associative array string. The string key and value are single quoted
The returned document will not be formatted yet. Use PhpAssocMap.Exploder.explode/1 or PhpAssocMap.Exploder.explode/2 to have it formatted.
Exmples
iex> PhpAssocMap.from_tuple([{"key", [{"another_key", "value"}]}])
"['key'=>['another_key'=>'value']]"
Parses an associative array string (or charlist) to a key-valued map. Both single and double quotes are supported.
Note: If the string starts with <?php return
, it'll be ignored
Exemples
iex> PhpAssocMap.to_map("['key' => ['another_key' => 'value']]")
%{"key" => %{"another_key" => "value"}}
iex> PhpAssocMap.to_map("<?php return ['key' => ['another_key' => 'value']];")
%{"key" => %{"another_key" => "value"}}
Parses an associative array string (or charlist) to a key-valued keyword list. Both single and double quotes are supported.
Note: If the string starts with <?php return
, it'll be ignored
Exemples
iex> PhpAssocMap.to_tuple("['key' => ['another_key' => 'value']]")
[{"key", [{"another_key", "value"}]}]
iex> PhpAssocMap.to_tuple("<?php return ['key' => ['another_key' => 'value']];")
[{"key", [{"another_key", "value"}]}]