Skip to content

Add script to convert JS arrays/objects to PHP associative array.#210

Merged
IvanMathy merged 5 commits intoIvanMathy:mainfrom
jtolj:js-to-php
Mar 28, 2021
Merged

Add script to convert JS arrays/objects to PHP associative array.#210
IvanMathy merged 5 commits intoIvanMathy:mainfrom
jtolj:js-to-php

Conversation

@jtolj
Copy link
Contributor

@jtolj jtolj commented Nov 27, 2020

I find myself needing to do this pretty often, so knocked together this script and thought I'd share.

Converts JS array to a flat PHP array [1,2,"3"] to [1,2,"3"].

Converts JS object to PHP associative array {a: 1, b: "2"} to ['a' => 1, 'b' => '2'].

Should work fine with arbitrarily deep nesting of arrays or objects.

Thanks for Boop!

PS -
Don't think there's a good way to do this without eval() or new Function()

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jtolj
Copy link
Contributor Author

jtolj commented Mar 24, 2021

@jutiss Nice catch, thanks :).

@IvanMathy
Copy link
Owner

Really cool stuff, thanks!

@IvanMathy IvanMathy merged commit 21544d1 into IvanMathy:main Mar 28, 2021
@jtolj jtolj deleted the js-to-php branch March 29, 2021 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants