0

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');
6
  • 1
    so are you using PHP to access the database? Commented Dec 22, 2011 at 6:27
  • these index az, ru and en are constant or not? Commented Dec 22, 2011 at 6:30
  • where does it comes 'az','ru' and 'en' , from database?? Commented Dec 22, 2011 at 6:30
  • @mathematical.coffee yes of course. Commented Dec 22, 2011 at 6:30
  • @GauravVashishtha is a language implementation using CSV in database Commented Dec 22, 2011 at 6:31

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

I tried your version but got error. before left delimeter is there while?
Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements in test.php on line 8
finally it worked. but i have more than 1 row. you said but could you show example pls??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.