php returning primary key values from array -


first sorry , please gentle, learning php , sat down code basic cms practice stuck.

i have site settings table contains following

option           | option_value        | setting site_name        | site name        | general site_description | site description | general site_keywords    | site keywords    | general 

i doing following select

"$results = select settings setting values general" 

my foreach loop

foreach ($results $result)           {              var_dump($result);          } 

i getting following results foreach loop

array(3) {   ["option"]=>   string(16) "site_description"   ["option_value"]=>   string(17) "my site description "   ["setting"]=>   string(7) "general" } array(3) {   ["option"]=>   string(13) "site_keywords"   ["option_value"]=>   string(14) "my site keywords "   ["setting"]=>   string(7) "general" } array(3) {   ["option"]=>   string(9) "site_name"   ["option_value"]=>   string(17) "my site name"   ["setting"]=>   string(7) "general" } 

my question is there way return results this

  ["option"]=>   string(16) "site_description"   ["option_value"]=>   string(17) "my site description "   ["setting"]=>   string(7) "general"    ["option"]=>   string(13) "site_keywords"   ["option_value"]=>   string(14) "my site keywords "   ["setting"]=>   string(7) "general"    ["option"]=>   string(9) "site_name"   ["option_value"]=>   string(17) "my site name"   ["setting"]=>   string(7) "general" 

so remove array(3) index , join them? sorry because english. maybe not correct word it, searching lot on net did not find solution.

could please out?

edit

so said

foreach ($results $result) {

    var_dump($result); } 

i getting following results foreach loop

array(3) {   ["option"]=>   string(16) "site_description"   ["option_value"]=>   string(17) "my site description "   ["setting"]=>   string(7) "general" } array(3) {   ["option"]=>   string(13) "site_keywords"   ["option_value"]=>   string(14) "my site keywords "   ["setting"]=>   string(7) "general" } array(3) {   ["option"]=>   string(9) "site_name"   ["option_value"]=>   string(17) "my site name"   ["setting"]=>   string(7) "general" } 

so try explain, because need pass results variable

so when loop way

 foreach ($results $result )      {       var_dump($result['site_name']) ;         } 

so when add site_name index in want show index option values, if way undefined index: site_name

no. can not. can join them wouldn't have result want because have 3 elements same key. how acces second elements option? not possible.

questionable if desireable.

i advise rethink why want that. maybe problem think have solveable without getting such array.

if want (as described in comments) array holding option_value each option, can rearrange array first.

$newarray = array(); foreach ($results $result)  {   $newarray[ $result['option'] ] = $result['option_value']; } var_dump($newarray); 

edit: reading edit thou, seems problem not know how access array data.

you have array:

array(3) {   ["option"]=>   string(9) "site_name"   ["option_value"]=>   string(17) "my site name"   ["setting"]=>   string(7) "general" } 

and try acces way:

var_dump($result['site_name']); 

but 'site_name' value, stored in array under key 'option'.

so expect content of $result['site_name']? if want "my site name" have call $result['option_value'] on array holding 'site_name'. solution above rearrange array give acces want, thou not want. want?


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -