CONVERT ARRAY TO LIST () AND SHORTHAND FOR ARRAY DESTRUCTURING

I have a php array of key => value, and I would lượt thích to store all the values into a list (like a python list) of values.I need it cause I have to lớn pass this danh mục of values khổng lồ a JQuery script.

Bạn đang xem: Convert array to list () and shorthand for array destructuring

Basically I have:

$var = Array ( <0> => 5 <1> => 7 <2> => 9 <3> => 10 )and I would lượt thích to have something like

$var = <5, 7, 9, 10>;When I điện thoại tư vấn from Jquery my variable:

var newvariable = "";The final goal is to have a Jquery danh sách like:

var newvariable = <5,7,9,10>;Is this possible in php?


*

*

*

*

I"m assuming you have a PHP array such as this:

$var = array ( 5, 7, 9, 10 );This would print, with var_dump:

array(4) <0>=> int(5) <1>=> int(7) <2>=> int(9) <3>=> int(10)PHP has a list() language constructor <1>. I don"t believe this is what you want though.

Since I"m not sure exactly how this is constructed, I"d suggest looking at the JSON functions <2> PHP has available which might be of help when interacting with jQuery.

Not a definitive answer but I hope it helps.

Xem thêm: Mua Sữa Tắm Hazeline Chính Hãng Giá Tốt Tại Bachhoaxanh, Sữa Tắm Hazeline Có Làm Trắng Da Không

<1> http://php.net/manual/en/function.list.php<2> http://php.net/manual/en/ref.json.php


mô tả
Follow
answered Feb trăng tròn 2017 at 12:27
*

Hugo MartinsHugo Martins
111 bronze badge
địa chỉ cửa hàng a bình luận |

Your Answer


Thanks for contributing an answer khổng lồ Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to lớn other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.


Draft saved
Draft discarded

Sign up or log in


Sign up using Google
Sign up using Facebook
Sign up using thư điện tử and Password
Submit

Post as a guest


Name
e-mail Required, but never shown


Post as a guest


Name
email

Required, but never shown


Post Your Answer Discard

By clicking “Post Your Answer”, you agree khổng lồ our terms of service, privacy policy & cookie policy


Not the answer you're looking for? Browse other questions tagged php arrays or ask your own question.


The Overflow Blog
Featured on Meta
Related
3926
Create ArrayList from array
4561
How vị I kiểm tra if an array includes a value in JavaScript?
2860
Deleting an element from an array in PHP
3684
How khổng lồ insert an công trình into an array at a specific index (JavaScript)
1942
How bởi you check if a variable is an array in JavaScript?
3545
Sort array of objects by string property value
3658
Loop through an array in JavaScript
4878
Reference — What does this symbol mean in PHP?
10331
How can I remove a specific vật phẩm from an array?
5274
For-each over an array in JavaScript
Hot Network Questions more hot questions

Question feed
Subscribe to RSS
Question feed to lớn subscribe khổng lồ this RSS feed, copy and paste this URL into your RSS reader.


lang-php
Stack Overflow
Products
Company
Stack Exchange Network
site thiết kế / logo © 2022 Stack Exchange Inc; user contributions licensed under cc by-sa. Rev2022.2.11.41438


Stack Overflow works best with JavaScript enabled
*

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device & disclose information in accordance with our Cookie Policy.