PhpAssocMap v1.0.0 PhpAssocMap View Source

Link to this section 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

Link to this section 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']]")
  [{{:string, 1, "key"}, [{{:string, 1, "another_key"}, {:string, 1, "value"}}]}]
Link to this function

from_map(map) View Source
from_map(map()) :: 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']]"
Link to this function

from_tuple(tuple) View Source
from_tuple([tuple()]) :: 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']]"
Link to this function

to_map(string) View Source
to_map(binary() | charlist()) :: any()

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"}}
Link to this function

to_tuple(string) View Source
to_tuple(binary() | charlist()) :: [tuple()]

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"}]}]