Someone
Someone

Reputation: 736

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');

Upvotes: 0

Views: 311

Answers (1)

xkeshav
xkeshav

Reputation: 54050

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

Upvotes: 3

Related Questions