dtm37893
2019-05-20 20:32
浏览 157
已采纳

将数组元素转换为单个字符串(PHP)

So basically, I use this to retrieve data

$sql = "SELECT * FROM user WHERE id = ".$_POST['id'];
$user = $this->oDb->selectQuery($sql);

^^ that is this:

$aResult = array();
        while($row = $res->fetch_assoc()) {
            $aResult[] = $row;
        }
        return $aResult;

So that would return this:

Array ( [0] => Array ( [id] => 11 [voornaam] => Franklin [tv] => Delano [achternaam] => Roosevelt ) ) 

How do I convert Franklin which is 'voornaam' and Delano which is 'tv' and Roosevelt which is 'achternaam'

to either $user['voornaam']
$user['tv']
$user['achternaam']

so it would result in echo $user['voornaam'] which would say Franklin

or either $voornaam
$tv
$achternaam

or it would result in echo $voornaam which would say Franklin

图片转代码服务由CSDN问答提供 功能建议

基本上,我用它来检索数据</ p>

  $  sql =“SELECT * FROM user WHERE id =”。$ _ POST ['id']; 
 $ user = $ this-&gt; oDb-&gt; selectQuery($ sql); 
 </ code> </ pre>  
 
 

^^就是这样:</ p>

  $ aResult = array(); 
 while($ row = $ res-&gt; fetch_assoc())  {
 $ aResult [] = $ row; 
} 
返回$ aResult; 
 </ code> </ pre> 
 
 

这样会返回:</ p> \ n

  Array([0] =&gt; Array([id] =&gt; 11 [voornaam] =&gt; Franklin [tv] =&gt; Delano [achternaam] =&gt; Roosevelt))
 <  / code> </ pre> 
 
 

如何转换Franklin,即'voornaam' 和Delano,即'tv' 和Roosevelt'achternaam'</ p>

 到$ user ['voornaam'] 
 $ user ['tv'] 
 $ user ['achternaam'] 
 
它会导致echo $ user ['voornaam']会说 富兰克林
 \既不是$ voornaam 
 $ tv 
 $ achternaam 
 \也不会导致echo $ voornaam,这会说Franklin 
 </ code> </ pre> 
 </  DIV>

2条回答 默认 最新

相关推荐 更多相似问题