简体   繁体   中英

How to create php array from MySQL column?

I have such table:

id | name                                 | link
---+--------------------------------------+---------------
1  |SAsasasdsa,Главная страница,Main page | addsad

I want to get array like that:

$arr = array('az'=>'SAsasasdsa','ru'=>'Главная страница','en'=>'Main page');

TRY

$qry = mysql_query('SELECT * FROM table');
//for multiple rows
$row = mysql_fetch_assoc($qry)) { $input[] = $row['name'] }
$key = array('az', 'ru', 'en');
foreach($input as $val) { 
  $output[] = array_combine($key,explode(',',$val));
}
echo "<pre>"; print_r($output);

Reference

array_combine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM