@toJson & @fromJson - JSON Conversion
The @toJson
and @fromJson
directives in Ahmed PHP Template Engine allow you to convert data to and from JSON format.
Syntax
data
: The PHP array or object to be converted into a JSON string.jsonString
: The JSON string to be converted into a PHP array.
Description
@toJson
converts an array or object into a JSON-encoded string.@fromJson
converts a JSON string back into a PHP array.Useful for handling API responses, data storage, and dynamic content manipulation.
Example
Convert PHP Array to JSON
Expected Output:
Convert JSON String to PHP Array
Expected Output:
Notes
@toJson
ensures proper JSON formatting for data exchange.@fromJson
automatically decodes valid JSON into an array.Ensure the JSON string is properly formatted to avoid errors.
Last updated