webguync Posted March 25, 2010 Share Posted March 25, 2010 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 More sharing options...
oni-kun Posted March 25, 2010 Share Posted March 25, 2010 $mysqlresult = '1,7,9,10,15'; $array = explode(',', $mysqlresult); print $array[2]; //9 print '<br/>' . print_r($array); Link to comment https://forums.phpfreaks.com/topic/196540-turning-mysql-data-into-an-array/#findComment-1031891 Share on other sites More sharing options...
o3d Posted March 25, 2010 Share Posted March 25, 2010 http://php.net/manual/en/function.explode.php Explode takes a string delimited by specified characters and creates an array. Please be more specific in what you want to do. Link to comment https://forums.phpfreaks.com/topic/196540-turning-mysql-data-into-an-array/#findComment-1031894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.