How to populate a two dimensional PHP array?

I'm using Wordpress and I have created a posts array using get_posts (a list of attachments IDs of type image).
This populates the array with the post IDs that I'm interested in. I would now like to add an associated item to each of the array entries so that I end up with something like this.
1234  ABCD
2343 FDRE
4324 HGRD

The first column is the postID and the second column is the associated string that I've added (from a lookup).
The reason for this is I would like to sort the array into ascending order on the second column which will then put my post IDs in the same order. When I display the images using the post ID, they will be displayed in the order defined by column 2.
Who is Participating?
Chris StanyonCommented:
Easiest option here may be to stick with a one-dimensional array, and to set the key to the ID:

$values = array();
$values[1234] = ABCD
$values[2343] = FDRE
$values[4324] = HGRD


foreach ($values as $id => $value):

Open in new window

ClintonKAuthor Commented:
Thanks. That does the job perfectly!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.