PHPackages                             phylogram/php\_to\_js\_converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phylogram/php\_to\_js\_converter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phylogram/php\_to\_js\_converter
================================

This package allows to generate javascript code from php, with literal code from strings, and automatic array, string, boolean, number and null conversion.

00PHP

Since Nov 3Pushed 6y ago1 watchersCompare

[ Source](https://github.com/phylogram/PHPToJSConverter)[ Packagist](https://packagist.org/packages/phylogram/php_to_js_converter)[ RSS](/packages/phylogram-php-to-js-converter/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

PHPToJSConverter: Generate JS Code from within Php
==================================================

[](#phptojsconverter-generate-js-code-from-within-php)

Description
-----------

[](#description)

This package allows to generate javascript code from php, with literal code from strings, and automatic array, string, boolean, number and null conversion.

Why
---

[](#why)

I used json\_encode to transform php arrays and more into javascript code. I would not write as strings, since I want to use phps object inherit features. However you can not pass javascript code through json\_encode, because it will be handled as strings.

Somehow I did not find any other implementation.

How
---

[](#how)

Pass your data to \\PHPToJSConverter\\JSConverter::to\_javascript(), if you need javascript code, use \\PHPToJSConverter\\Items\\LiteralJSCode()

Examples
--------

[](#examples)

### 1.

[](#1)

```
echo 'let one = ' . PHPToJSConverter\JSConverter::to_javascript(['a' => 1, 'f' => new \PHPToJSConverter\Items\LiteralJSCode(
