Jump to content

turning MySQL data into an array


webguync

Recommended Posts

I have data which is being pulled from a MySQL table called 'incorrect_resp', the results would look something like '1,7,9,10,15' in the MySQL field.

 

I need to extract that data into an array like below for variable $a. I think explode() will get me there, but not sure how to go about coding to get me where I need to be. I looked in the PHP manual for explode(), but didn't see any examples that were doing what I needed to do.

 

also for $b this isn't being pulled from a MySQL db, but not sure how to handle populating $b with what corresponds to $a. The association will always be constant. Hope this makes sense!

 

<?php
$a = array('1', '7', '9','10,'15');
$b = array('I-A', 'I-D', 'III-C',IV-A,'VI');
$c = array_combine($a, $b);

echo($c);
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.