suppose I have the follwing matrix data:
2 3
4 5
6 7
8 9
How to insert them into a 2d php array, can anybody help me with that, I am new to php 2d array, any help will be greatly appreciated!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you actually want a 2D array or do you want your first columns to be the keys?
You can do this:
Then you can access it like this:
You can also do this:
Read this and post back with a more specific question if you are not understanding somewhere.
https://www.php.net/manual/en/language.types.array.php
Also, the reason the comments are asking you where you got the data is because you can automate much of this process. If you are pulling it from a database, then the 2D arrays can be made automatically. Otherwise, the process I just did above is very manual. I don’t know think I’ve ever made an array like this in a production environment. They are always in for or foreach loops.