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
https://forums.phpfreaks.com/topic/196540-turning-mysql-data-into-an-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.