Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Mar 28, 2021

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()

@sonarcloud
Copy link

sonarcloud bot commented Nov 27, 2020

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

Scripts/jsToPhp.js Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Mar 24, 2021

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